# for M&B .901

from header_common import *
from header_dialogs import *
from header_operations import *
from header_parties import *
from header_items import *
from header_item_modifiers import *
from header_skills import *
from header_triggers import *
from ID_troops import *
from ID_party_templates import *
from header_colors import *
from module_constants import *


####################################################################################################################
# During a dialog, the dialog lines are scanned from top to bottom.
# If the dialog-line is spoken by the player, all the matching lines are displayed for the player to pick from.
# If the dialog-line is spoken by another, the first (top-most) matching line is selected.
#
#  Each dialog line contains the following fields:
# 1) Dialogue partner: This should match the person player is talking to.
#    Usually this is a troop-id.
#    You can also use a party-template-id by appending '|party_tpl' to this field.
#    Use the constant 'anyone' if you'd like the line to match anybody.
#    Appending '|plyr' to this field means that the actual line is spoken by the player
#    Appending '|other(troop_id)' means that this line is spoken by a third person on the scene.
#       (You must make sure that this third person is present on the scene)
#
# 2) Starting dialog-state:
#    During a dialog there's always an active Dialog-state.
#    A dialog-line's starting dialog state must be the same as the active dialog state, for the line to be a possible candidate.
#    If the dialog is started by meeting a party on the map, initially, the active dialog state is "start"
#    If the dialog is started by speaking to an NPC in a town, initially, the active dialog state is "start"
#    If the dialog is started by helping a party defeat another party, initially, the active dialog state is "party_relieved"
#    If the dialog is started by liberating a prisoner, initially, the active dialog state is "prisoner_liberated"
#    If the dialog is started by defeating a party led by a hero, initially, the active dialog state is "enemy_defeated"
#    If the dialog is started by a trigger, initially, the active dialog state is "event_triggered"
# 3) Conditions block (list): This must be a valid operation block. See header_operations.py for reference.  
# 4) Dialog Text (string):
# 5) Ending dialog-state:
#    If a dialog line is picked, the active dialog-state will become the picked line's ending dialog-state.
# 6) Consequences block (list): This must be a valid operation block. See header_operations.py for reference.
####################################################################################################################

dialogs = [
    [trp_bandit_leader,"start",[(neq,"$bandits_joined",1)],"So you want to be a bandit?","bandit_1",[]],
    [anyone|plyr,"bandit_1",[],"I'm here, aren't I?","bandit_2",[]],
    [anyone,"bandit_2",[(try_for_range,reg1,"fac_commoners","fac_end_fac"),
                                                    (set_relation,"fac_player_faction",reg1,-10),
                                            (try_end),
                                            (set_relation,"fac_player_faction","fac_outlaws",10),
                                            (assign,"$bandits_joined",1)],
    "Ha! I like your attitude. You're in.","close_window",[]],
    [trp_bandit_leader,"start",[],"I have nothing to say to you now.","close_window",[]],
    [trp_bandit_slaver,"start",[],"Got any prisoners to sell?","bandit_sell_prisoners",[]],
    [anyone|plyr,"bandit_sell_prisoners",[],"Yeah, have a look.","bandit_sell_prisoners_2",[(change_screen_trade_prisoners)]],
    [anyone|plyr,"bandit_sell_prisoners",[],"No way, man.","bandit_no_sell",[]],
    [anyone,"bandit_sell_prisoners_2",[],"Thanks.","close_window",[]],
    [anyone,"bandit_no_sell",[],"Your loss.","close_window",[]],
    [trp_kingmaker,"start",[],"Greetings, {playername}. I am the Kingmaker.","km_begin",[]],
    [anyone,"km_begin",[],"What would you wish of me?","km1",[]],
	# [anyone|plyr,'km1',[],'Run script_game_start','km_reset',
		# [
			# (try_for_parties,':party_no'),
				# (gt,':party_no',269),
				# (remove_party,':party_no'),
			# (try_end),
			# (call_script,'script_game_start'),
			# ]],
	# [anyone,'km_reset',[],'It is done.','km_begin',[]],
	[anyone|plyr,'km1',[],'Test scene','km_room',[]],
    [anyone,'km_room',[],'As you wish.','close_window',
		[
			(set_jump_entry,0),
			(set_jump_mission,'mt_town_default'),
			(jump_to_scene,'scn_merchant_hall'),
			(change_screen_mission),
			]],
	[anyone|plyr,"km1",[],"Make me uber.","km_uber",[]],
    [anyone,"km_uber",[(add_xp_as_reward,10000000),(troop_add_gold,0,1000000)],"Very well. Thou art uber.","km_begin",[]], #return to kingmaker menu
	[anyone|plyr,'km1',[],'Increase my fame by 1000','km_fame',[]],
	[anyone,'km_fame',[],'Done.','km_begin',
		[
			(call_script,'script_object_modify_slot',obj_troop,'trp_player',slot_player_renown,op_add,1000),
			]],
	# [anyone|plyr,'km1',[],'Run script game start','km_ra',[(call_script,'script_game_start')]],
	# [anyone,'km_ra',[],'Done','km1',
		# [
			# ]],
	[anyone|plyr,'km1',[],'Test troop outfit','km_of',
		[
			]],
	[anyone,'km_of',[],'Very well...','outfitter_pre_start',[]],
	[anyone|plyr,'km1',[],'Init test facilities','km_init_fac',
		[
			(call_script,'script_initialize_facility',north_kyoto,ft_farm,'str_fac_farm',null),
			(call_script,'script_initialize_facility',north_kyoto,ft_lumber_mill,'str_fac_lumber_mill',null),
			(call_script,'script_initialize_facility',north_kyoto,ft_flour_mill,'str_fac_flour_mill',null),
			(call_script,'script_initialize_facility',north_kyoto,ft_paper_mill,'str_fac_paper_mill',null),
			(call_script,'script_town_storehouse_add_items',north_kyoto,'itm_wooden_tools',10000),
			(call_script,'script_town_storehouse_add_items',north_kyoto,'itm_metal_tools',10000),
			(call_script,'script_town_storehouse_add_items',north_kyoto,'itm_wheat',10000),
			(call_script,'script_town_storehouse_add_items',north_kyoto,'itm_hemp',10000),
			(call_script,'script_initialize_facility',east_kyoto,ft_foundry,'str_fac_foundry',null),
			(call_script,'script_initialize_facility',east_kyoto,ft_blacksmith,'str_fac_blacksmith',null),
			(call_script,'script_initialize_facility',east_kyoto,ft_woodshop,'str_fac_woodshop',null),
			(call_script,'script_initialize_facility',east_kyoto,ft_smokehouse,'str_fac_smokehouse',null),
			(call_script,'script_town_storehouse_add_items',east_kyoto,'itm_wooden_tools',10000),
			(call_script,'script_town_storehouse_add_items',east_kyoto,'itm_metal_tools',10000),
			(call_script,'script_town_storehouse_add_items',east_kyoto,'itm_iron_ore',10000),
			(call_script,'script_town_storehouse_add_items',east_kyoto,'itm_copper_ore',10000),
			(call_script,'script_town_storehouse_add_items',east_kyoto,'itm_charcoal',50000),
			(call_script,'script_town_storehouse_add_items',east_kyoto,'itm_salted_fish',10000),
			(call_script,'script_town_storehouse_add_items',north_kyoto,'itm_wood',10000),
			(call_script,'script_initialize_facility',west_kyoto,ft_potter,'str_fac_potter',null),
			(call_script,'script_initialize_facility',west_kyoto,ft_iron_mine,'str_fac_iron_mine',null),
			(call_script,'script_initialize_facility',west_kyoto,ft_silver_mine,'str_fac_silver_mine',null),
			(call_script,'script_town_storehouse_add_items',west_kyoto,'itm_wooden_tools',10000),
			(call_script,'script_town_storehouse_add_items',west_kyoto,'itm_metal_tools',10000),
			(call_script,'script_town_storehouse_add_items',north_kyoto,'itm_wood',10000),
			]],
	[anyone,'km_init_fac',
		[
			],
		'Done','km1',
		[
			]],
	[anyone|plyr,'km1',[],'Check test demand and storehouse arrays','km_arrays1',
		[
			]],
	[anyone,'km_arrays1',
		[
			(str_clear,s10),
			(str_clear,s11),
			(party_get_slot,':demand_array',north_kyoto,slot_town_demand_array),
			(party_get_slot,':storehouse_array',north_kyoto,slot_town_storehouse_array),
			(str_store_string,s10,'@{s10}North Kyoto^Demands:^'),
			(str_store_string,s11,'@{s11}Supply:^'),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_peek',':demand_array',':array_index'),
				(assign,':demand_qty','$return'),
				(call_script,'script_array_peek',':storehouse_array',':array_index'),
				(assign,':supply_qty','$return'),
				(store_add,':item_no',':array_index',trade_goods_begin),
				(try_begin),
					(gt,':demand_qty',0),
					(assign,reg10,':demand_qty'),
					(str_store_item_name,s12,':item_no'),
					(str_store_string,s10,'@{s10}{s12}: {reg10}, '),
				(try_end),
				(try_begin),
					(gt,':supply_qty',0),
					(assign,reg10,':supply_qty'),
					(str_store_item_name,s13,':item_no'),
					(str_store_string,s11,'@{s11}{s13}: {reg10}, '),
				(try_end),
			(try_end),
			(str_store_string,s10,'@{s10}^{s11}'),
			],
		'{s10}','km_arrays2',
		[
			]],
	[anyone,'km_arrays2',
		[
			(str_clear,s10),
			(str_clear,s11),
			(party_get_slot,':demand_array',east_kyoto,slot_town_demand_array),
			(party_get_slot,':storehouse_array',east_kyoto,slot_town_storehouse_array),
			(str_store_string,s10,'@{s10}East Kyoto^Demands:^'),
			(str_store_string,s11,'@{s11}Supply:^'),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_peek',':demand_array',':array_index'),
				(assign,':demand_qty','$return'),
				(call_script,'script_array_peek',':storehouse_array',':array_index'),
				(assign,':supply_qty','$return'),
				(store_add,':item_no',':array_index',trade_goods_begin),
				(try_begin),
					(gt,':demand_qty',0),
					(assign,reg10,':demand_qty'),
					(str_store_item_name,s12,':item_no'),
					(str_store_string,s10,'@{s10}{s12}: {reg10}, '),
				(try_end),
				(try_begin),
					(gt,':supply_qty',0),
					(assign,reg10,':supply_qty'),
					(str_store_item_name,s13,':item_no'),
					(str_store_string,s11,'@{s11}{s13}: {reg10}, '),
				(try_end),
			(try_end),
			(str_store_string,s10,'@{s10}^{s11}'),
			],
		'{s10}','km_arrays3',
		[
			]],
	[anyone,'km_arrays3',
		[
			(str_clear,s10),
			(str_clear,s11),
			(party_get_slot,':demand_array',west_kyoto,slot_town_demand_array),
			(party_get_slot,':storehouse_array',west_kyoto,slot_town_storehouse_array),
			(str_store_string,s10,'@{s10}West Kyoto^Demands:^'),
			(str_store_string,s11,'@{s11}Supply:^'),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_peek',':demand_array',':array_index'),
				(assign,':demand_qty','$return'),
				(call_script,'script_array_peek',':storehouse_array',':array_index'),
				(assign,':supply_qty','$return'),
				(store_add,':item_no',':array_index',trade_goods_begin),
				(try_begin),
					(gt,':demand_qty',0),
					(assign,reg10,':demand_qty'),
					(str_store_item_name,s12,':item_no'),
					(str_store_string,s10,'@{s10}{s12}: {reg10}, '),
				(try_end),
				(try_begin),
					(gt,':supply_qty',0),
					(assign,reg10,':supply_qty'),
					(str_store_item_name,s13,':item_no'),
					(str_store_string,s11,'@{s11}{s13}: {reg10}, '),
				(try_end),
			(try_end),
			(str_store_string,s10,'@{s10}^{s11}'),
			],
		'{s10}','km1',
		[
			]],
	[anyone|plyr,'km1',[],'Destroy facilities','km_desfac',
		[
			(try_for_range,':town','p_city_2','p_city_5'),
				(party_get_slot,':facilities_array',':town',slot_town_facility_array),
				(party_get_slot,':num_facilities',':facilities_array',array_value_high_index),
				(try_for_range,':unused',0,':num_facilities'),
					(call_script,'script_array_queue',':facilities_array'),
					(assign,':cur_facility','$return'),
					(call_script,'script_gc_destroy_facility',':cur_facility'),
				(try_end),
			(try_end),
			]],
	[anyone,'km_desfac',[],'Done.','km1',
		[
			]],
	[anyone|plyr,'km1',[],'Spawn traders','km_trade',
		[
			(try_for_range,':town','p_city_2','p_city_5'),
				(call_script,'script_cf_town_generate_caravan',':town',-111),
			(try_end),
			]],
	[anyone,'km_trade',[],'Done','km1',
		[
			]],
	# [anyone|plyr,'km_array2',[],'Peek random','km_array3',
		# [
			# (store_random_in_range,':array_index',1,11),
			# (call_script,'script_array_peek','$g_debug_array',':array_index'),
			# (assign,reg10,'$return'),
			# (display_message,'@{reg10}',debug_text),
			# ]],
	# [anyone|plyr,'km_array2',[],'Poke random','km_array3',
		# [
			# (store_random_in_range,':array_index',1,11),
			# (store_random_in_range,':array_value',11,21),
			# (call_script,'script_array_poke','$g_debug_array',':array_index',':array_value'),
			# (assign,reg10,':array_value'),
			# (display_message,'@{reg10}',debug_text),
			# ]],
	# [anyone|plyr,'km_array2',[],'Push random','km_array3',
		# [
			# (store_random_in_range,':array_value',21,31),
			# (call_script,'script_array_push','$g_debug_array',':array_value'),
			# (assign,reg10,':array_value'),
			# (display_message,'@{reg10}',debug_text),
			# ]],
	# [anyone|plyr,'km_array2',[],'Pop','km_array3',
		# [
			# (call_script,'script_array_pop','$g_debug_array'),
			# (assign,reg10,'$return'),
			# (display_message,'@{reg10}',debug_text),
			# ]],
	# [anyone|plyr,'km_array2',[],'Quit','km_begin',[]],
	# [anyone,'km_array3',[],'Looping back...','km_array2',[]],
	
	# [anyone|plyr,"km1",[],"Modify a faction attitude.","km2a",[]],
    # [anyone,"km2a",[],"Which faction?","km3a",[]],
    # [anyone|plyr,"km3a",[],"Hosokawa","km4a",[(assign,"$fac_to_mod","fac_hosokawa")]],
    # [anyone|plyr,"km3a",[],"Akamatsu","km4a",[(assign,"$fac_to_mod","fac_akamatsu")]],
    # [anyone|plyr,"km3a",[],"Hosokawa-Hatakeyama","km4a",[(assign,"$fac_to_mod","fac_hosokawa_hatakeyama")]],
    # [anyone|plyr,"km3a",[],"Takeda","km4a",[(assign,"$fac_to_mod","fac_takeda")]],
    # [anyone|plyr,"km3a",[],"Kyogoku","km4a",[(assign,"$fac_to_mod","fac_kyogoku")]],
    # [anyone|plyr,"km3a",[],"Yamana","km4a",[(assign,"$fac_to_mod","fac_yamana")]],
    # [anyone|plyr,"km3a",[],"Ishikki","km4a",[(assign,"$fac_to_mod","fac_ishikki")]],
    # [anyone|plyr,"km3a",[],"Yamana-Hatakeyama","km4a",[(assign,"$fac_to_mod","fac_hosokawa")]],
    # [anyone|plyr,"km3a",[],"Rokkaku","km4a",[(assign,"$fac_to_mod","fac_rokkaku")]],
    # [anyone|plyr,"km3a",[],"Toku","km4a",[(assign,"$fac_to_mod","fac_toki")]],
    # [anyone|plyr,"km3a",[],"Shiba","km4a",[(assign,"$fac_to_mod","fac_shiba")]],
    # [anyone,"km4a",[],"What will this faction's attitude be toward you?","km5a",[]],
    # [anyone|plyr,"km5a",[],"Generous","km6a",[(assign,"$new_att",att_generous)]],
    # [anyone|plyr,"km5a",[],"Friendly","km6a",[(assign,"$new_att",att_friendly)]],
    # [anyone|plyr,"km5a",[],"Cautious","km6a",[(assign,"$new_att",att_cautious)]],
    # [anyone|plyr,"km5a",[],"Secretive","km6a",[(assign,"$new_att",att_secretive)]],
    # [anyone|plyr,"km5a",[],"Defensive","km6a",[(assign,"$new_att",att_defensive)]],
    # [anyone|plyr,"km5a",[],"Offensive","km6a",[(assign,"$new_att",att_offensive)]],
    # [anyone|plyr,"km5a",[],"Hostile","km6a",[(assign,"$new_att",att_hostile)]],
    # [anyone,"km6a",[],"Very well. It is done.","km_begin",[(faction_set_slot,"$fac_to_mod",slot_faction_att_to_player,"$new_att")]], #return to kingmaker menu
    # [anyone|plyr,"km1",[],"Modify a town attitude.","km2b",[]],
    # [anyone,"km2b",[],"Which town?","km3b",[]],
    # [anyone|plyr,"km3b",[],"Itami","km4b",[(assign,"$town_to_mod",itami)]],
    # [anyone|plyr,"km3b",[],"Utano","km4b",[(assign,"$town_to_mod",utano)]],
    # [anyone|plyr,"km3b",[],"Santo","km4b",[(assign,"$town_to_mod",santo)]],
    # [anyone|plyr,"km3b",[],"Oya","km4b",[(assign,"$town_to_mod",oya)]],
    # [anyone|plyr,"km3b",[],"Takase","km4b",[(assign,"$town_to_mod",takase)]],
    # [anyone|plyr,"km3b",[],"Miyazu","km4b",[(assign,"$town_to_mod",miyazu)]],
    # [anyone|plyr,"km3b",[],"Hidaka","km4b",[(assign,"$town_to_mod",hidaka)]],
    # [anyone|plyr,"km3b",[],"Takada","km4b",[(assign,"$town_to_mod",takada)]],
    # [anyone|plyr,"km3b",[],"Fujidera","km4b",[(assign,"$town_to_mod",fujidera)]],
    # [anyone,"km4b",[],"What will this town's attitude be toward you?","km5b",[]],
    # [anyone|plyr,"km5b",[],"Generous","km6b",[(assign,"$new_att",att_generous)]],
    # [anyone|plyr,"km5b",[],"Friendly","km6b",[(assign,"$new_att",att_friendly)]],
    # [anyone|plyr,"km5b",[],"Cautious","km6b",[(assign,"$new_att",att_cautious)]],
    # [anyone|plyr,"km5b",[],"Secretive","km6b",[(assign,"$new_att",att_secretive)]],
    # [anyone|plyr,"km5b",[],"Defensive","km6b",[(assign,"$new_att",att_defensive)]],
    # [anyone|plyr,"km5b",[],"Offensive","km6b",[(assign,"$new_att",att_offensive)]],
    # [anyone|plyr,"km5b",[],"Hostile","km6b",[(assign,"$new_att",att_hostile)]],
    # [anyone,"km6b",[],"Very well. It is done.","km_begin",[(party_set_slot,"$town_to_mod",slot_town_att_to_player,"$new_att")]], #return to kingmaker menu
    # [anyone|plyr,"km1",[],"Update patrol attitudes.","km2d",[]],
    # [anyone,"km2d",[(try_for_range,reg1,"p_city_1","p_temple_1"),
                        # (party_get_slot,reg2,reg1,slot_town_patrol_active),
                        # (eq,reg2,1),
                        # (assign,"$pin_town",reg1),
                        # (call_script,"script_update_patrol_attitude"),
                    # (try_end)],
     # "Very well. It is done.","km_begin",[]], #return to kingmaker menu
    # [anyone|plyr,"km1",[],"Reset default attitudes.","km2c",[]],
    # [anyone,"km2c",[(try_for_range,reg1,"fac_neutral","fac_merchants"),
                        # (faction_set_slot,reg1,slot_faction_att_to_player,att_cautious),
                    # (try_end),
                    # (try_for_range,reg2,"p_city_1","p_temple_1"),
                        # (party_set_slot,reg2,slot_town_att_to_player,att_cautious),
                        # (party_get_slot,reg3,reg2,slot_town_patrol_active),
                        # (eq,reg3,1),
                        # (assign,"$pin_town",reg2),
                        # (call_script,"script_update_patrol_attitude"),
                    # (try_end)],
     # "Very well. It is done.","km_begin",[]], #return to kingmaker menu
    [anyone|plyr,"km1",[],"Leave.","km_end",[]],
    [anyone,"km_end",[],"Good day to you, then.","close_window",[]],
	[anyone,'start',
		[
			(store_conversation_troop,'$g_conversation_troop'),
			(is_between,'$g_conversation_troop',outfitters_begin,outfitters_end),
			],
		'Greetings, {Tono/Hime}...','outfitter_pre_start',
		[]],
	[anyone,'outfitter_pre_start',[],'How may I be of service?','outfitter_start',[]],
	[anyone|plyr,'outfitter_start',[],"I'd like to outfit some troops",'outfit_select1',[]],
	[anyone,'outfit_select1',[],'Who would you like to outfit?','outfit_select_troop',[]],
	[anyone|plyr|repeat_for_troops,'outfit_select_troop',
			[
				(store_repeat_object,':troop_no'),
				(is_between,':troop_no',outfit_troops_begin,outfit_troops_end),
				(main_party_has_troop,':troop_no'),
				(str_store_troop_name,s10,':troop_no'),
				],
			'{s10}','outfit_select_type_start',
			[
				(store_repeat_object,'$g_troop_to_be_outfitted'),
				]],
	[anyone|plyr,'outfit_select_troop',[],'Never mind','outfit_end',[]],
	[anyone,'outfit_select_type_start',[],'How will you outfit this troop?','outfit_select_type',[]],
	[anyone|plyr|repeat_for_troops,'outfit_select_type',
		[
			(eq,'$g_troop_to_be_outfitted','trp_armed_peasant'), # upgrading armed peasant to ashigaru
			(store_repeat_object,':type_code'),
			(is_between,':type_code',0,3), # types: 0 - yari, 1 - yumi, 2 - crossbow
			(try_begin),
				(try_begin),
					(eq,':type_code',0),
					(str_store_string,s10,'@Yari'),
				(else_try),
					(eq,':type_code',1),
					(str_store_string,s10,'@Yumi'),
				(else_try),
					(eq,':type_code',2),
					(str_store_string,s10,'@Dokyu'),
				(try_end),
			(try_end),
			],
		'{s10}','outfit_select_uniform_start',
		[
			(store_repeat_object,'$g_outfitted_troop_type'),
			]],
	[anyone|plyr|repeat_for_troops,'outfit_select_type',
		[
			(eq,'$g_troop_to_be_outfitted','trp_samurai'), # upgrading samurai to specialized samurai
			(store_repeat_object,':type_code'),
			(is_between,':type_code',0,5), # types: 0 - yari, 1 - yumi, 2 - kenshi, 3 - light cav, 4 - heavy cav
			(try_begin),
				(try_begin),
					(eq,':type_code',0),
					(str_store_string,s10,'@Yari'),
				(else_try),
					(eq,':type_code',1),
					(str_store_string,s10,'@Yari'),
				(else_try),
					(eq,':type_code',2),
					(str_store_string,s10,'@Kenshi'),
				(else_try),
					(eq,':type_code',3),
					(str_store_string,s10,'@Light Cavalry'),
				(else_try),
					(eq,':type_code',4),
					(str_store_string,s10,'@Heavy Cavalry'),
				(try_end),
			(try_end),
			],
		'{s10}','outfit_select_uniform_start',
		[
			(store_repeat_object,'$g_outfitted_troop_type'),
			]],
	[anyone|plyr,'outfit_select_type',[],'Never mind','outfit_end',[]],
	[anyone,'outfit_select_uniform_start',[],'To what faction will this troop belong?','outfit_select_uniform',[]],
	[anyone|plyr|repeat_for_troops,'outfit_select_uniform',
			[
				(store_repeat_object,':color_code'),
				(is_between,':color_code',0,3),
				(try_begin),
					(eq,':color_code',0),
					(str_store_string,s10,'@Hosokawa'),
				(else_try),
					(eq,':color_code',1),
					(str_store_string,s10,'@Yamana'),
				(else_try),
					(eq,':color_code',2),
					(str_store_string,s10,'@Neutral'),
				(try_end),
				],
			'{s10}','outfit_cost_start',
			[
				(store_repeat_object,'$g_outfitted_troop_color'),
				]],
	[anyone,'outfit_cost_start',
		[
			(call_script,'script_clear_temp_array','trp_temp_array_a',20),
			(call_script,'script_clear_temp_array','trp_temp_array_b',20),
			(assign,':index',0),
			(try_for_range,':troop_no','trp_t2_spear_ashigaru_h','trp_t2_spear_samurai_h'),
				(troop_set_slot,'trp_temp_array_a',':index',':troop_no'),
				(val_add,':index',1),
			(try_end),
			(assign,':index',0),
			(try_for_range,':troop_no','trp_t2_spear_samurai_h','trp_t3_spear_ashigaru_h'),
				(troop_set_slot,'trp_temp_array_b',':index',':troop_no'),
				(val_add,':index',1),
			(try_end),
			(try_begin),
				(eq,'$g_troop_to_be_outfitted','trp_armed_peasant'),
				(store_mul,':temp_array_index','$g_outfitted_troop_color',3),
				(val_add,':temp_array_index','$g_outfitted_troop_type'),
				(troop_get_slot,'$g_target_outfitted_troop','trp_temp_array_a',':temp_array_index'),
			(else_try),
				(eq,'$g_troop_to_be_outfitted','trp_samurai'),
				(store_mul,':temp_array_index','$g_outfitted_troop_color',5),
				(val_add,':temp_array_index','$g_outfitted_troop_type'),
				(troop_get_slot,'$g_target_outfitted_troop','trp_temp_array_b',':temp_array_index'),
			(try_end),
			(troop_equip_items,'$g_target_outfitted_troop'),
			(call_script,'script_calculate_troop_outfit_cost','$g_target_outfitted_troop'),
			(assign,'$g_outfit_cost',reg0),
			],
		'The cost of outfitting this troop is {reg0}. Is that acceptable?','outfit_cost_confirm',[]],
	[anyone|plyr,'outfit_cost_confirm',
		[
			(store_troop_gold,':troop_gold','trp_player'),
			(ge,':troop_gold','$g_outfit_cost'),
			],
		'Yes','outfit_troop',
		[
			(troop_remove_gold,'trp_player','$g_outfit_cost'),
			(party_remove_members,'p_main_party','$g_troop_to_be_outfitted',1),
			(party_add_members,'p_main_party','$g_target_outfitted_troop',1),
			]],
	[anyone|plyr,'outfit_cost_confirm',[],'No','outfit_end',[]],
	[anyone,'outfit_troop',[],'Your troop has been outfitted','outfitter_pre_start',[]],
	[anyone,'outfit_end',[],'As you wish. Good day','close_window',[]],
    [anyone,'start',
     [
         (party_get_template_id,':template','$g_encountered_party'),
         (eq,':template','pt_fort'),
         (store_conversation_troop,':troop_id'),
         (party_slot_eq,'$g_encountered_party',slot_castle_commander,':troop_id'),
         ],
     'Greetings, {tono/hime}...','fort_status',[]],
    [anyone,'fort_status',[],'How can I help you?','fort_status2',[]],
    [anyone|plyr,'fort_status2',[(party_slot_lt,'$g_encountered_party',slot_castle_progress,1000)],'How is the construction going?','fort_con_status',[]],
    [anyone|plyr,'fort_status2',
     [
         (party_slot_ge,'$g_encountered_party',slot_castle_progress,1000),
         (party_slot_neq,'$g_encountered_party',slot_castle_patrol_active,1),
         ],
     'I wish to send forth a patrol','fort_spawn_patrol',[]],
    [anyone|plyr,'fort_status2',
     [
         (party_slot_ge,'$g_encountered_party',slot_castle_progress,1000),
         (party_slot_eq,'$g_encountered_party',slot_castle_patrol_active,1),
         ],
     'I wish to call_back the patrol','fort_patrol_return',[]],
    [anyone|plyr,'fort_status2',[],'What is the status of the fort?','fort_garrison_status',[]],
    [anyone|plyr,'fort_status2',[],'I wish to deposit some money into the treasury.','deposit_money',[]],
    [anyone|plyr,'fort_status2',[],'I wish to trade some troops.','trade_troops',[]],
    [anyone|plyr,'fort_status2',[],'Thank you for your time.','fort_leave',[]],
    [anyone,'fort_leave',[],'Good day, {tono/hime}.',"close_window",[]],
    [anyone,'fort_con_status',
     [
         (str_clear,1),
         (party_get_slot,':progress','$g_encountered_party',slot_castle_progress),
         (try_begin),
             (is_between,':progress',0,250),
             (str_store_string,1,'str_castle_progress_1'),
         (else_try),
             (is_between,':progress',250,500),
             (str_store_string,1,'str_castle_progress_2'),
         (else_try),
             (is_between,':progress',500,750),
             (str_store_string,1,'str_castle_progress_3'),
         (else_try),
             (is_between,':progress',750,1000),
             (str_store_string,1,'str_castle_progress_4'),
         (else_try),
             (str_store_string,1,'str_castle_progress_complete'),
         (try_end),
         ],
     "{s1}",'fort_status',[]],
    [anyone,'fort_garrison_status',
     [
         (party_get_num_companions,reg1,'$g_encountered_party'),
         (party_get_slot,reg2,'$g_encountered_party',slot_castle_treasury),
         ],
     "The garrison is currently {reg1} men strong, and there is {reg2} mon in the treasury.",'fort_status',[]],
    [anyone,'deposit_money',[],'How much do you wish to deposit?','deposit_amount',[]],
    [anyone|plyr|repeat_for_troops,'deposit_amount',
		[
			(store_repeat_object,'$g_deposit_amount'),
			(this_or_next|eq,'$g_deposit_amount',10),
			(this_or_next|eq,'$g_deposit_amount',50),
			(eq,'$g_deposit_amount',100),
			(store_mul,':temp_deposit_amount','$g_deposit_amount',10),
			(store_troop_gold,':available_cash','trp_player'),
			(ge,':available_cash',':temp_deposit_amount'),
			(assign,reg10,':temp_deposit_amount'),
			],
		"{reg10} mon",'deposit_money2',
		[
			(store_repeat_object,'$g_deposit_amount'),
			(val_mul,'$g_deposit_amount',10),
			(troop_remove_gold,'trp_player','$g_deposit_amount'),
			(call_script,'script_object_modify_slot',obj_party,'$g_encountered_party',slot_castle_treasury,op_add,'$g_deposit_amount'),
			]],
    [anyone|plyr,'deposit_amount',[],"Never mind",'fort_status',[]],
    [anyone,'deposit_money2',[],'Many thanks.','fort_status',[]],
    [anyone,'trade_troops',[],'Have a look at the garrison.','fort_status',[(change_screen_exchange_members,0)]],
    [anyone,'fort_spawn_patrol',[],'Very good, {tono/hime}. What shall be the patrol strength?','fort_patrol_str',[]],
    [anyone|plyr,'fort_patrol_str',[],'Send out half the men.','fort_patrol_muster',[(assign,'$fort_patrol_str',2)]],
    [anyone|plyr,'fort_patrol_str',[],'Send out the whole garrison.','fort_patrol_muster',[(assign,'$fort_patrol_str',1)]],
    [anyone,'fort_patrol_muster',[],'And what shall be their orders?','fort_patrol_orders',[]],
    [anyone|plyr,'fort_patrol_orders',[],'Patrol the fort.','fort_patrol_finish',
     [(party_set_slot,'$g_encountered_party',slot_castle_patrol_orders,ai_bhvr_patrol_party),
      (party_set_slot,'$g_encountered_party',slot_castle_patrol_target,'$g_encountered_party')]],
    [anyone|plyr,'fort_patrol_orders',[],'Attack the nearest village.','fort_patrol_finish',
     [(party_set_slot,'$g_encountered_party',slot_castle_patrol_orders,ai_bhvr_attack_party),
      (call_script,'script_get_nearest_enemy_village','$g_encountered_party'),
      (party_set_slot,'$g_encountered_party',slot_castle_patrol_target,'$return')]],
    [anyone|plyr,'fort_patrol_orders',[],'Follow my party.','fort_patrol_finish',
     [(party_set_slot,'$g_encountered_party',slot_castle_patrol_orders,ai_bhvr_patrol_party),
      (party_set_slot,'$g_encountered_party',slot_castle_patrol_target,0)]],
    [anyone,'fort_patrol_finish',[(call_script,'script_spawn_fort_patrol','$g_encountered_party','$fort_patrol_str')],
     'Excellent, {tono/hime}. The patrol has been sent forth.','fort_status',[]],
    [anyone,'fort_patrol_return',
     [
		 (party_get_slot,':fort_patrol','$g_encountered_party',slot_castle_patrol),
         (party_set_ai_behavior,':fort_patrol',ai_bhvr_travel_to_party),
         (party_set_ai_object,':fort_patrol','$g_encountered_party'),
         ],
     "Very good, {tono/hime}. The patrol is returning.",'fort_status',[]],
    [party_tpl|pt_builder,'start',[(get_party_ai_behavior,':bhvr','$g_encountered_party'),
                                   (eq,':bhvr',ai_bhvr_hold)],
     "Shall we be off?",'start_builders',[]],
    [anyone|plyr,'start_builders',
     [
         (party_set_ai_behavior,'$g_encountered_party',ai_bhvr_attack_party),
         (party_set_ai_object,'$g_encountered_party',0),
         ],
     'Yes. Follow me.','close_window',[]],
    [party_tpl|pt_builder,'start',[],'Is this the spot where the outpost will be built?','outpost_1',[]],
    [anyone|plyr,'outpost_1',[],'Yes, begin building here.','build_outpost',[]],
    [anyone|plyr,'outpost_1',[],"No, let's keep moving.",'outpost_2',[]],
    [anyone,'build_outpost',
     [
         (call_script,'script_build_fort','$g_encountered_party'),
         ],
     'Very well, {tono/hime}. We will start construction immediately.','close_window',[]],
    [anyone,'outpost_2',[],'As you wish.','close_window',[(assign,'$g_leave_encounter',1)]],
	[trp_geomancer,'start',[],'Kon-nichi-wa, {Tono/Hime}...','geomancer_start',[]],
	[anyone,'geomancer_start',[],'I coordinate the local builders. How can I help you?','geomancer_2',[]],
	[anyone|plyr,'geomancer_2',[],"I'd like to hire a team of builders to construct an outpost.",'geomancer_builders',[]],
	[anyone|plyr,'geomancer_2',[],'Never mind.','close_window',[]],
	[anyone,'geomancer_builders',[],"Very good. The initial outlay for the building team and materials is 1000 koku, or 360000 mon. Yearly upkeep for the structure is 1000 koku, or 7000 mon per week, plus any additional costs for troop housing. Are you prepared for this considerable committment?",'geomancer_builders_2',[]],
	[anyone|plyr,'geomancer_builders_2',
		[
			(store_troop_gold,':available_cash',0),
			(ge,':available_cash',360000),
			],
		"Yes. Where do I sign?",'geomancer_spawn_builders',[(troop_remove_gold,0,360000)]],
	[anyone|plyr,'geomancer_builders_2',[],"On second thought, this isn't such a good idea.",'geomancer_end',[]],
	[anyone,'geomancer_spawn_builders',[(call_script,'script_spawn_builder','$g_encountered_party')],
		"It has beena pleasure doing business with you. The geomancer's entourage is waiting for your outside the city.",'close_window',[]],
	[anyone,'geomancer_end',[],'A wise decision, {Tono/Hime}. Good day to you.','close_window',[]],
	[trp_temple_1_priest,'start',[(check_quest_active,'qst_subclass_monk')],'May the peace of Buddha light your path.','priest_start',[]],
	[anyone,'priest_start',[],'How can I help?','priest_talk',[]],
	[anyone|plyr,'priest_talk',[],"I'd like to recruit some monks",'priest_recruit',[]],
	[anyone|plyr,'priest_talk',[],'Never mind','priest_end',[]],
	[anyone,'priest_recruit',[],'Of course.','priest_start',
		[(set_mercenary_source_party,'p_temple_1_mercs'),(change_screen_buy_mercenaries)]],
	[trp_temple_1_priest,'start',
		[
			(quest_slot_neq,'qst_defeat_mountain_bandits',slot_quest_complete,true),
			(check_quest_succeeded,'qst_defeat_mountain_bandits')
			],
		'You have returned without re-entering the wheel of karma. I trust things went well?','priest_bandits_end',[]],
	[anyone|plyr,'priest_bandits_end',[],'They did. The mountain bandits will trouble you no more','priest_bandits_reward',[]],
	[anyone,'priest_bandits_reward',[],'A thousand blessings from Buddha, {playername}. This deed shall not be forgotten.','close_window',
		[
			(call_script,'script_modify_fame',100),
			(call_script,'script_end_quest','qst_defeat_mountain_bandits'),
			(call_script,'script_object_modify_slot',obj_quest,'qst_defeat_mountain_bandits',slot_quest_complete,op_asn,true),
			]],
	[trp_temple_1_priest,'start',[],'Greetings, travellers.','priest_intro_1',[]],
	[anyone|plyr,'priest_intro_1',[],'And what might your name be?','priest_intro_2',[]],
	[anyone,'priest_intro_2',[],'Names are transient, impermanent things which tie us to the material world. I have no name, but you may call me Hyogo-bo.','priest_intro_3',[]],
	[anyone|plyr,'priest_intro_3',[],'I wish to become one of your order.','priest_intro_4',[]],
	[anyone|plyr,'priest_intro_3',
		[
			(quest_slot_neq,'qst_defeat_mountain_bandits',slot_quest_complete,true),
			],
		'Do you have any jobs that need doing?','priest_fight_bandits',[]],
	[anyone,'priest_intro_4',[],'While we welcome new intiates, I must tell you this is not to be undertaken lightly. The Eightfold Path is long and arduous. You are required to relinquish all your worldly wealth, and any troops you have in your employ, plus give up your previous ways of life.','priest_join_choice',[]],
	[anyone|plyr,'priest_join_choice',[],"Yes, I'm sure.",'priest_join',[]],
	[anyone,'priest_join',
		[
			(store_troop_gold,reg1,'trp_player'),
			(troop_remove_gold,'trp_player',reg1),
			(party_get_num_companion_stacks,':stack_no','p_main_party'),
			(try_for_range,':unused',0,':stack_no'),
				(party_stack_get_troop_id,':troop_id','p_main_party',':unused'),
				(neg|troop_is_hero,':troop_id'),
				(party_stack_get_size,':troop_count','p_main_party',':unused'),
				(party_remove_members,'p_main_party',':troop_id',':troop_count'),
			(try_end),
			(start_quest,'qst_subclass_monk'),
			(cancel_quest,'qst_subclass_shinobi'),
			(cancel_quest,'qst_subclass_bandit'),
			],
		'Very well. You are a member of the Tendai Order.','close_window',[]],
	[anyone|plyr,'priest_join_choice',[],"You know, maybe this isn't such a good idea",'priest_end',[]],
	[anyone,'priest_fight_bandits',[],'Yes, actually. The mountain bandits which swarm around sacred Hiei-yama are a continual thorn in the side of the pilgrims which travel here. Defeat them, and your karma will be increased.','priest_bandits_accept',[]],
	[anyone|plyr,'priest_bandits_accept',
		[
			(store_random_in_range,reg1,1,11),
			(val_add,reg1,20),
			(store_num_parties_destroyed_by_player,'$num_mountain_bandits','pt_mountain_bandits'),
			(quest_set_slot,'qst_defeat_mountain_bandits',slot_quest_troop_1_cnt,reg1),
			],
		'You request is reasonable. I will do all I can to ease the journey of the pilgrims.','priest_end',
		[
			(call_script,'script_start_quest','qst_defeat_mountain_bandits'),
			]],
	[anyone|plyr,'priest_bandits_accept',[],"Are you mad? No one can defeat them. I'll have to pass.",'priest_deny_quest',[]],
	[anyone,'priest_deny_quest',[],'So be it. Good day.','close_window',[]],
	[anyone,'priest_end',[],'Very well. Good luck to you.','close_window',[]],
    [trp_haruko,"start",
		[
			(troop_slot_eq,'trp_haruko',slot_troop_has_joined,1),
			(check_quest_active,'qst_companion_training'),
			(neg|check_quest_succeeded,'qst_companion_training'),
			],
		"Please speak with the sensei.","close_window",[]],
    [trp_haruko,"start",[(troop_slot_eq,'trp_haruko',slot_troop_at_inn,1),
                         (neg|main_party_has_troop,reg1)],"Do you want me to rejoin you now?","member_inn_talk",[]],
    [trp_haruko,"start",[(troop_slot_eq,'trp_haruko',slot_troop_has_joined,1)],"What are we waiting for? Let's go!","close_window",[]],
    [trp_haruko,"start",[],"Hey, can I join you?","haruko_join",[]],
    [anyone|plyr,"haruko_join",[],"Sure.","haruko_joined",[]],
    [anyone|plyr,"haruko_join",[],"No way.","haruko_no_join",[]],
    [anyone,"haruko_joined",[(neg|hero_can_join,0)],"It seems you don't have room for me. Too bad.","close_window",[]],
    [anyone,"haruko_joined",[],"Great. And don't worry about me in a fight. I'm pretty good with a naginata.",
     "close_window",[(troop_join,"trp_haruko"),(remove_troop_from_site,"trp_haruko"),(troop_set_slot,"trp_haruko",slot_troop_has_joined,1)]],
    [anyone,"haruko_no_join",[],"Well, poo on you.","close_window",[]],
    [trp_shinbo,"start",
		[
			(troop_slot_eq,'trp_shinbo',slot_troop_has_joined,1),
			(check_quest_active,'qst_companion_training'),
			(neg|check_quest_succeeded,'qst_companion_training'),
			],
	"Please speak with the sensei.","close_window",[]],
    [trp_shinbo,"start",[(troop_slot_eq,'trp_shinbo',slot_troop_at_inn,1),(neg|main_party_has_troop,"trp_shinbo")],"Do you want me to rejoin you now?","member_inn_talk",[]],
    [trp_shinbo,"start",[(troop_slot_eq,'trp_shinbo',slot_troop_has_joined,1)],"Though time is but an illusion, it waits for no man, nonetheless.","close_window",[]],
    [trp_shinbo,"start",[(troop_slot_eq,"trp_shinbo",slot_troop_intro,1)],"I see you have returned. Did you get a Tendai charm?","shinbo_5",[]],
    [trp_shinbo,"start",[],"Greetings, traveller. May the peace of Buddha be with you.","shinbo_1",[]],
    [anyone|plyr,"shinbo_1",[],"Hello, monk. I am {playername}. Say, you don't happen to know any of the healing arts, do you?","shinbo_2",[(troop_set_slot,"trp_shinbo",slot_troop_intro,1)]],
    [anyone,"shinbo_2",[],"As a matter of fact, I do.","shinbo_3",[]],
    [anyone|plyr,"shinbo_3",[],"I don't suppose you'd like to join my little band? I could certainly use one such as yourself.","shinbo_4",[]],
    [anyone,"shinbo_4",[],"Well, it is time for me to begin a pilgrimage around the countryside. I could certainly use the protection. However, I am not permitted to leave without a Tendai charm.","shinbo_5",[]],
    [anyone|plyr,"shinbo_5",[(player_has_item,"itm_tendai_charm")],"Here, I have one.","shinbo_6a",[]],
    [anyone|plyr,"shinbo_5",[],"I will return with one.","shinbo_6b",[]],
    [anyone,"shinbo_6a",[(neg|hero_can_join,0)],"It would appear you have no more room. Come back when you do.","close_window",[]],
    [anyone,"shinbo_6a",[(hero_can_join,0)],"Very well, {playername}. Let us be off.","close_window",
     [
		(troop_remove_item,"trp_player","itm_tendai_charm"),
		(troop_add_item,"trp_shinbo","itm_tendai_charm"),
		(troop_join,"trp_shinbo"),
		(remove_troop_from_site,"trp_shinbo"),
		(troop_set_slot,'trp_shinbo',slot_troop_has_joined,1)]],
    [anyone,"shinbo_6b",[],"I will await your return.","close_window",[]],
    [trp_tsuruhiro,"start",
		[
			(troop_slot_eq,'trp_tsuruhiro',slot_troop_has_joined,1),
			(check_quest_active,'qst_companion_training'),
			(neg|check_quest_succeeded,'qst_companion_training'),
			],
		"Please speak with the sensei.","close_window",[]],
    [trp_tsuruhiro,"start",[(troop_slot_eq,'trp_tsuruhiro',slot_troop_at_inn,1),(neg|main_party_has_troop,"trp_tsuruhiro")],"Do you want me to rejoin you now?","member_inn_talk",[]],
    [trp_tsuruhiro,"start",[(troop_slot_eq,'trp_tsuruhiro',slot_troop_has_joined,1)],"My vengence will not be sated until the bandits who killed my lord are defeated. Let us get to it.","close_window",[]],
    [trp_tsuruhiro,"start",[],"...Please, leave me to my sake.","tsuruhiro_1",[]],
    [anyone|plyr,"tsuruhiro_1",[],"You seem down on your luck, tomodachi-san. Tell me your story, and I'll buy you another.","tsuruhiro_2",[]],
    [anyone,"tsuruhiro_2",[],"I am grateful. I was my lord's best samurai. Countless were the heads I took for his honor. I was on a secret mission to strike down his rival. Sometime while I was gone, a sickness struck the town. My wife and son were cut down, and my lord fell so ill he could not stand. Bandits raided, killing everyone including my lord. Now, I am ronin, wandering and masterless. I should commit seppuku, but I cannot bring myself to do it. I am shamed, but my heart burns to avenge the death of my lord. My friend sake dulls both pains.","tsuruhiro_3",[]],
    [anyone|plyr,"tsuruhiro_3",[],"Perhaps I could give you the chance to avenge your lord. Would you join me?","tsuruhiro_4",[]],
    [anyone,"tsuruhiro_4",[(neg|hero_can_join,0)],"Nothing would give me greater satisfaction. Perhaps then my soul can find rest. But you have no more room.","close_window",[]],
    [anyone,"tsuruhiro_4",[(hero_can_join,0)],"Nothing would give me greater satisfaction. Perhaps then my soul can find rest.","tsuruhiro_5",[]],
    [anyone|plyr,"tsuruhiro_5",[],"Then come, and let us seek your vengence.","close_window",[(troop_join,"trp_tsuruhiro"),(remove_troop_from_site,"trp_tsuruhiro"),(troop_set_slot,'trp_tsuruhiro',slot_troop_has_joined,1)]],
    [trp_akikane,"start",
		[
			(troop_slot_eq,'trp_akikane',slot_troop_has_joined,1),
			(check_quest_active,'qst_companion_training'),
			(neg|check_quest_succeeded,'qst_companion_training'),
			],
		"Please speak with the sensei.","close_window",[]],
    [trp_akikane,"start",[(troop_slot_eq,'trp_akikane',slot_troop_at_inn,1),(neg|main_party_has_troop,"trp_akikane")],"Do you want me to rejoin you now?","member_inn_talk",[]],
    [trp_akikane,"start",[(troop_slot_eq,'trp_akikane',slot_troop_has_joined,1)],"You linger here in this place...perhaps you fear the real ultimate power of Akikane?","close_window",[]],
    [trp_akikane,"start",[(troop_slot_eq,"trp_akikane",slot_troop_intro,1)],"Did you bring my ya?","akikane_5",[]],
    [trp_akikane,"start",[],"So, another would-be hero comes to challenge the mighty Akikane.","akikane_1",[]],
    [anyone|plyr,"akikane_1",[],"Who? I've never heard of you.","akikane_2",[]],
    [anyone,"akikane_2",[],"Are you trying to insult me?!! I am Akikane, greatest archer in all of Nihon!","akikane_3",[]],
    [anyone|plyr,"akikane_3",[],"I am {playername}, and I know a boaster when I hear one.","akikane_4",[(troop_set_slot,"trp_akikane",slot_troop_intro,1)]],
    [anyone,"akikane_4",[],"**He laughs** You are either couragous or a fool, {playername}. But, you have amused me. Bring me a quiver of ya, and I will travel with you.","akikane_5",[]],
    [anyone|plyr,"akikane_5",[(player_has_item,"itm_ya")],"I have your arrows.","akikane_6a",[]],
    [anyone|plyr,"akikane_5",[],"Wait here and I'll bring you your arrows.","akikane_6b",[]],
    [anyone,"akikane_6a",[(neg|hero_can_join,0)],"Yes, you do. But you have no room for me.","close_window",[]],
    [anyone,"akikane_6a",[(hero_can_join,0)],"Excellent. Now you will see my true might!","close_window",
     [
		(troop_remove_item,"trp_player","itm_ya"),
		(troop_add_item,"trp_akikane","itm_ya"),
		(troop_join,"trp_akikane"),
		(remove_troop_from_site,"trp_akikane"),
		(troop_set_slot,'trp_akikane',slot_troop_has_joined,1)]],
    [anyone,"akikane_6b",[],"Hah! You amuse me even more by making me wait.","close_window",[]],
    [trp_yamamatsu,"start",[(troop_slot_eq,'trp_yamamatsu',slot_troop_at_inn,1),(neg|main_party_has_troop,"trp_yamamatsu")],"Do you want me to rejoin you now?","member_inn_talk",[]],
    [trp_yamamatsu,"start",[(main_party_has_troop,"trp_yamamatsu")],"I can not serve waiting in this inn. We must go.","close_window",[]],
    [trp_yamamatsu,"start",[(troop_slot_eq,"trp_yamamatsu",slot_troop_intro,1)],"I see you have returned. Do you have it?","yamamatsu_9",[]],
    [trp_yamamatsu,"start",[],"Kon-nichiwa.","yamamatsu_1",[]],
    [anyone|plyr,"yamamatsu_1",[],"Good day to you. Your serious demeanor marks you as a man of great skill.","yamamatsu_2",[]],
    [anyone,"yamamatsu_2",[],"Your insight is impressive, stranger. I am Yamamatsu, Master of the Eight Schools.","yamamatsu_3",[]],
    [anyone|plyr,"yamamatsu_3",[],"I am {playername}. It is an honor to meet one of such learning. Would you be willing to join me?","yamamatsu_4",[(troop_set_slot,"trp_yamamatsu",slot_troop_intro,1)]],
    [anyone,"yamamatsu_4",[],"I have long since exhausted any challenge that might have been in this place. Perhaps the road will offer greater promise. However, my services do not come without price.","yamamatsu_5",[]],
    [anyone|plyr,"yamamatsu_5",[],"What is your price?","yamamatsu_6",[]],
    [anyone,"yamamatsu_6",[],"A sword from the smith in Aioi. It is said there is none greater. Bring me one of his blades, and I will serve you to my death.","yamamatsu_7",[]],
    [anyone|plyr,"yamamatsu_7",[],"This will take some time.","yamamatsu_8",[]],
    [anyone,"yamamatsu_8",[],"Then I will wait here until then.","close_window",[]],
    [anyone|plyr,"yamamatsu_9",[(player_has_item,"itm_sharp_wave")],"Yes. Here it is.","yamamatsu_9b",[]],
	[anyone,'yamamatsu_9b',[],'What is that?','yamamatsu_9c',[]],
	[anyone|plyr,'yamamatsu_9c',[],'I know, I know. This is what the smith in Aioi made.','yamamatsu_9d',[]],
	[anyone,'yamamatsu_9d',[],"Really? Where did he learn to mask swords, anyway? It looks like it came out of an oni's mouth.",'yamamatsu_9e',[]],
	[anyone|plyr,'yamamatsu_9e',[],'Funny, I said the same thing.','yamamatsu_10',[]],
    [anyone|plyr,"yamamatsu_9",[],"I do not have it yet.","yamamatsu_8",[]],
    [anyone,"yamamatsu_10",[(neg|hero_can_join,0)],"Well, you have kept your word, so I shall keep mine. However, you have no more room.","close_window",[]],
    [anyone,"yamamatsu_10",[(hero_can_join,0)],"Well, you have kept your word, so I shall keep mine. Come, let us be off.","close_window",
	[
		(troop_remove_item,"trp_player","itm_sharp_wave"),
		(troop_add_item,"trp_yamamatsu","itm_sharp_wave"),
		(troop_join,"trp_yamamatsu"),
		(remove_troop_from_site,"trp_yamamatsu"),
		(troop_set_slot,'trp_yamamatsu',slot_troop_has_joined,1)]],
    
    [trp_village_2_kokujin,"start",
		[
			(quest_slot_eq,'qst_sanda_bandits',slot_quest_complete,true),
			],
		"Welcome back, {playername}-{dono/hime}...","kokujin_start",[]],
    [trp_village_2_kokujin,"start",[(check_quest_active,'qst_sanda_bandits')],"Well, is it finished?","sanda_quest_in_progress",[]],
    [trp_village_2_kokujin,"start",[],"Greetings, stranger.","sanda_start",[]],
    [anyone|plyr,"sanda_start",[],"This village seems deserted. What's going on?","sanda_quest_begin",[]],
    [anyone,"sanda_quest_begin",[],"There is a bandit camp near here that constantly harasses our villagers as they go to market. We don't dare send anyone out for fear of them being captured or killed. Hyogo is the nearest market town, and who knows what dangers lie further afield. Please, rid us of these bandits.","sanda_quest_2",[]],
    [anyone|plyr,"sanda_quest_2",[],"Of course. I will do what I can.","sanda_quest_accepted",[]],
    [anyone|plyr,"sanda_quest_2",[],"Sorry, I can't.","sanda_quest_denied",[]],
    [anyone,"sanda_quest_accepted",[],"Thank you, {Tono/Hime}. We look forward to your success.","close_window",
		[
			(store_conversation_troop,reg1),
			(store_num_parties_destroyed_by_player,'$g_num_bandits_defeated','pt_bandits'),
			(quest_set_slot,'qst_sanda_bandits',slot_quest_giver,reg1),
			(str_store_troop_name,s1,reg1),
			(setup_quest_giver,'qst_sanda_bandits',s1),
			(call_script,'script_start_quest',"qst_sanda_bandits"),
			]
		],
    [anyone,"sanda_quest_denied",[],"I see. Perhaps another, more courageous warrior will help us.","close_window",[]],
    [anyone|plyr,"sanda_quest_in_progress",[(check_quest_succeeded,'qst_sanda_bandits')],
     "Yes. I have taken care of your bandit problem.","sanda_quest_complete",[]],
    [anyone|plyr,"sanda_quest_in_progress",[],
     "Not yet. I still have work to do.","sanda_quest_in_progress_2",[]],
    [anyone,"sanda_quest_complete",[],"Oh, wonderful! You have helped us more than you know. Thank you.","close_window",
		[
			(call_script,'script_end_quest',"qst_sanda_bandits"),
			(quest_set_slot,'qst_sanda_bandits',slot_quest_complete,true),
			(add_xp_as_reward,300),
			(troop_add_gold,"trp_player",200),
			(call_script,'script_object_modify_slot',obj_troop,'trp_player',slot_player_renown,op_add,5),
			]],
    [anyone,"sanda_quest_in_progress_2",[],"Well, get to it. Time is running out for us.","close_window",[]],
#Daimyo dialogs
	[anyone,'start',
		[
			(store_conversation_troop,'$g_conversation_troop'),
			(this_or_next|eq,'$g_conversation_troop','trp_hosokawa_katsumoto'),
			(eq,'$g_conversation_troop','trp_yamana_souzen'),
			(store_troop_faction,':daimyo_faction','$g_conversation_troop'),
			(faction_get_slot,':enemy_faction',':daimyo_faction',slot_faction_enemy_faction),
			(str_store_faction_name,s11,':daimyo_faction'),
			(display_message,'@{s11}',debug_text),
			# (faction_get_slot,':faction_quest',':daimyo_faction',slot_faction_quest),
			# (faction_get_slot,':enemy_faction_quest',':enemy_faction',slot_faction_quest),
			(assign,':dialog_valid',false),
			(try_begin),
				(check_quest_active,'qst_class_merchant'),
				(faction_get_slot,':faction_quest_letter',':daimyo_faction',slot_faction_letter),
				(player_has_item,':faction_quest_letter'),
				(assign,'$g_talk_context',tc_daimyo_merchant),
				(assign,':dialog_valid',true),
			(else_try),
				(check_quest_active,'qst_class_ronin'),
				(faction_get_slot,':faction_quest_letter',':daimyo_faction',slot_faction_letter),
				(player_has_item,':faction_quest_letter'),
				(assign,'$g_talk_context',tc_daimyo_ronin_choice),
				(assign,':dialog_valid',true),
			(else_try),
				(faction_slot_eq,':daimyo_faction',slot_faction_joined,true),
				(faction_get_slot,':faction_quest_letter',':daimyo_faction',slot_faction_letter),
				(player_has_item,':faction_quest_letter'),
				(assign,'$g_talk_context',tc_daimyo_shugo_assigned),
				(assign,':dialog_valid',true),
			(else_try),
				(faction_slot_eq,':enemy_faction',slot_faction_joined,false),
				(faction_get_slot,':faction_quest_letter',':daimyo_faction',slot_faction_letter),
				(player_has_item,':faction_quest_letter'),
				(faction_slot_eq,':daimyo_faction',slot_faction_joined,false),
				(this_or_next|check_quest_active,'qst_defeat_pirates'),
				(check_quest_active,'qst_intro_kuge_deliver_msg'),
				(this_or_next|check_quest_succeeded,'qst_defeat_pirates'),
				(check_quest_succeeded,'qst_intro_kuge_deliver_msg'),
				(assign,'$g_talk_context',tc_daimyo_join_faction),
				(assign,':dialog_valid',true),
			(else_try),
				(faction_slot_eq,':enemy_faction',slot_faction_joined,false),
				(faction_get_slot,':faction_quest_letter',':daimyo_faction',slot_faction_letter),
				(player_has_item,':faction_quest_letter'),
				(faction_slot_eq,':daimyo_faction',slot_faction_joined,false),
				(this_or_next|check_quest_active,'qst_defeat_pirates'),
				(check_quest_active,'qst_intro_kuge_deliver_msg'),
				(this_or_next|neg|check_quest_succeeded,'qst_defeat_pirates'),
				(neg|check_quest_succeeded,'qst_intro_kuge_deliver_msg'),
				(assign,'$g_talk_context',tc_daimyo_invite_quest_active),
				(assign,':dialog_valid',true),
			(else_try),
				(faction_slot_eq,'fac_hosokawa',slot_faction_joined,false),
				(faction_slot_eq,'fac_yamana',slot_faction_joined,false),
				(faction_get_slot,':faction_quest_letter',':daimyo_faction',slot_faction_letter),
				(str_store_item_name,s11,':faction_quest_letter'),
				(display_message,'@{s11}',debug_text),
				(player_has_item,':faction_quest_letter'),
				(assign,'$g_talk_context',tc_daimyo_faction_invite),
				(assign,':dialog_valid',true),
			(try_end),
			(eq,':dialog_valid',true),
			],
		'Well, {playername}...','daimyo_start',[]],
    [anyone,"daimyo_start",
		[
			(eq,'$g_talk_context',tc_daimyo_shugo_assigned)
			],
     "I have instructed you to report to your shugo. Why are you here?","close_window",
		[
			(store_troop_faction,':daimyo_faction','$g_conversation_troop'),
			(faction_get_slot,':faction_letter',':daimyo_faction',slot_faction_letter),
			(troop_remove_item,'trp_player',':faction_letter'),
			]],
	[anyone,'daimyo_start',
		[
			(eq,'$g_talk_context',tc_daimyo_faction_invite),
			],
		'I understand you would like to serve under me','daimyo_faction_join_start',[]],
	[anyone|plyr,'daimyo_faction_join_start',[],'Yes, Tono','daimyo_faction_join_2',[]],
	[anyone,'daimyo_faction_join_2',
		[
			(this_or_next|check_quest_active,'qst_class_bushi'),
			(check_quest_active,'qst_class_kuge'),
			(try_begin),
				(check_quest_active,'qst_class_bushi'),
				(str_store_string,s10,'@{playername}-sama'),
			(else_try),
				(check_quest_active,'qst_class_kuge'),
				(str_store_string,s10,'@O-bugyo-sama'),
			(try_end),
			],
		'Though you have already sworn your allegiance to me, {s10}, there is one final test you must complete to prove your loyalty.',
		'daimyo_faction_join_3',[]],
	[anyone|plyr,'daimyo_faction_join_3',[],'Whatever you ask, Tono-sama, I will succeed','daimyo_faction_join_4',[]],
	[anyone,'daimyo_faction_join_4',
		[
			(str_clear,s10),
			(try_begin),
				(check_quest_active,'qst_class_bushi'),
				(assign,'$g_daimyo_intro_quest','qst_defeat_pirates'),
				(store_num_parties_destroyed_by_player,'$num_river_pirates','pt_river_pirates'),
				(store_troop_faction,':daimyo_faction','$g_conversation_troop'),
				(faction_get_slot,':enemy_faction',':daimyo_faction',slot_faction_enemy_faction),
				(str_store_faction_name,s11,':enemy_faction'),
				(str_store_string,s10,'@To the south of Kyoto along the north shore of the Yodo River, a band of pirates constanly harasses passing travellers going to and from Kyoto and the temples. These ruffians are secretly in league with the {s11}. Rend them assunder utterly, and I will consider you to be my retainer.'),
			(else_try),
				(check_quest_active,'qst_class_kuge'),
				(assign,'$g_daimyo_intro_quest','qst_intro_kuge_deliver_msg'),
				(quest_set_slot,'qst_intro_kuge_deliver_msg',slot_quest_target_troop,'trp_kameyama_shugo'),
		        (quest_set_slot,'qst_intro_kuge_deliver_msg',slot_quest_target_party,kameyama),
		        (str_store_troop_name,s11,"trp_kameyama_shugo"),
				(str_store_party_name,s12,kameyama),
				(str_store_string,s10,'@Deliver this message to {s11} of {s12} and I will consider you one of us. Be wary; the road is riddled with bandits.'),
			(try_end),
			],
		'Good. {s10}','daimyo_faction_join_5',
		[
			(quest_set_slot,'$g_daimyo_intro_quest',slot_quest_giver,'$g_conversation_troop'),
			(str_store_troop_name,s13,'$g_conversation_troop'),
			(setup_quest_giver,'$g_daimyo_intro_quest',s13),
			(setup_quest_text,'$g_daimyo_intro_quest'),
			(call_script,'script_start_quest','$g_daimyo_intro_quest'),
			]],
	[anyone|plyr,'daimyo_faction_join_5',[],'I will complete this mission, or die trying.','daimyo_faction_join_6',[]],
	[anyone,'daimyo_faction_join_6',[],"You're enthusiasm pleases me, but loyal men are difficult to find. Take these men with you, as a demonstration of how I treat my retainers, and some money for their pay and provision.",'daimyo_faction_join_7',
		[
			(store_troop_faction,':daimyo_faction','$g_conversation_troop'),
			(try_begin),
				(eq,':daimyo_faction','fac_hosokawa'),
				(party_add_members,'p_main_party','trp_t3_spear_ashigaru_h',8),
				(party_add_members,'p_main_party','trp_t3_bow_ashigaru_h',7),
			(else_try),
				(eq,':daimyo_faction','fac_yamana'),
				(party_add_members,'p_main_party','trp_t3_spear_ashigaru_y',8),
				(party_add_members,'p_main_party','trp_t3_bow_ashigaru_y',7),
			(try_end),
			(troop_add_gold,'trp_player',5000),
			]],
	[anyone|plyr,'daimyo_faction_join_7',[],'You are too generous, Tono. You have my thanks.','daimyo_faction_join_8',[]],
	[anyone,'daimyo_faction_join_8',[],'Good. Now be gone, and earn your reward.','close_window',[]],
    [anyone,"daimyo_start",
		[
			(eq,'$g_talk_context',tc_daimyo_invite_quest_active),
			],
     "If you want my allegience, it is unwise to tary.","close_window",[]],
    [anyone,"daimyo_start",
		[
			(eq,'$g_talk_context',tc_daimyo_ronin_choice),
			],
     "I am of two minds regarding you, Ronin. I could allow you to become my retainer, but there is also a special assignment only one with your...unique skills could undertake. I will leave the choice to you.",
	 "daimyo_ronin_choice",[]],
	 [anyone|plyr,'daimyo_ronin_choice',[],'I seek only to serve you, Tono. Please allow me to become your retainer.','daimyo_ronin_become_samurai',[]],
	 [anyone,'daimyo_ronin_become_samurai',
		[
			(store_troop_faction,':daimyo_faction','$g_conversation_troop'),
			(faction_get_slot,':enemy_faction',':daimyo_faction',slot_faction_enemy_faction),
			(str_store_faction_name,s11,':enemy_faction'),
			],
		'Very well. To the south along the Yodo River a group of river rats is colluding with the {s11} to disrupt trade to Kyoto. Defeat them, and I will consider you my retainer.',
		'daimyo_faction_join_4',
		[
			(str_store_troop_name,s12,'$g_conversation_troop'),
			(setup_quest_giver,'qst_defeat_pirates',s12),
			(setup_quest_text,'qst_defeat_pirates'),
			(call_script,'script_start_quest','qst_defeat_pirates'),
			]],
	 [anyone|plyr,'daimyo_ronin_choice',[],'This...other option intrigues me, Tono. Please tell me more.','ronin_become_investigator',[]],
	 [anyone,'ronin_become_investigator',
		[
			(store_troop_faction,':daimyo_faction','$g_conversation_troop'),
			(faction_get_slot,':enemy_faction',':daimyo_faction',slot_faction_enemy_faction),
			(str_store_faction_name,s11,':enemy_faction'),
			],
		'Excellent, {playername}. The bandit problem has gotten out of hand, and the {s11} do not make the task of controlling them any easier. I charge you with investigaing and rooting out the source of these hoodlums, and put a stop to them once and for all.',
		'ronin_investigator',
		[]],
	[anyone|plyr,'ronin_investigator',[],'Even as ronin, my purpose is to serve, Tono.','ronin_assign_shugo',[]],
	[anyone,'ronin_assign_shugo',
		[
			(store_troop_faction,':daimyo_faction','$g_conversation_troop'),
			(str_store_troop_name,s12,'$g_conversation_troop'),
			(call_script,'script_join_faction',':daimyo_faction','qst_class_ronin'),
			(cancel_quest,'qst_class_ronin'),
			(setup_quest_text,'qst_class_ronin_investigator'),
			(call_script,'script_start_quest','qst_class_ronin_investigator'),
			],
		'I admire your spirit, {playername}. Report to {s1} of {s2} to receive your assignments. Now go, and rid Japan of this menace.','close_window',[]],
	 [anyone,"daimyo_start",
		[
			(eq,'$g_talk_context',tc_daimyo_merchant),
			],
     "You have impressive spirit for coming here, Chounin, but I have no use for you. Now, go.",
     "close_window",
		[
			(store_troop_faction,':daimyo_faction','$g_conversation_troop'),
			(faction_get_slot,':faction_letter',':daimyo_faction',slot_faction_letter),
			(player_has_item,':faction_letter'),
			(troop_remove_item,'trp_player',':faction_letter'),
			]],
    [anyone,"daimyo_start",
		[
			(eq,'$g_talk_context',tc_daimyo_join_faction),
			(store_troop_faction,':daimyo_faction','$g_conversation_troop'),
			(faction_get_slot,':enemy_faction',':daimyo_faction',slot_faction_enemy_faction),
			(str_store_faction_name,s12,':enemy_faction'),
			],
     "Though you are already one of us, you have finally come into your full service to me. Do you renew your oath to me, to wage war against our enemy, the {s12}?",
     "swear_daimyo",[]],
    [anyone|plyr,"swear_daimyo",[],"I swear. From now on your enemies are my enemies.", "swear_daimyo_accepted",[]],
    [anyone|plyr,"swear_daimyo",[],"Forgive me, but I cannot.", "swear_denied",[]],
    [anyone,"swear_daimyo_accepted",
		[
			(store_troop_faction,':daimyo_faction','$g_conversation_troop'),
			(str_store_faction_name,s13,':daimyo_faction'),
			],
		"Then I welcome you among our ranks. {playername}. From now on, you are a retainer of the {s13}.",
		"swear_daimyo_3",
		[
	        (store_troop_faction,':daimyo_faction','$g_conversation_troop'),
			(try_begin),
				(check_quest_active,'qst_class_bushi'),
				(assign,':class','qst_class_bushi'),
			(else_try),
				(check_quest_active,'qst_class_kuge'),
				(assign,':class','qst_class_kuge'),
			(try_end),
	        (call_script,'script_join_faction',':daimyo_faction',':class'),
			(call_script,'script_end_quest','$g_daimyo_intro_quest'),
	        ]],
    [anyone,"swear_daimyo_3",
		[
			(str_clear,s10),
			(troop_get_slot,':player_lord','trp_player',slot_player_lord),
			(troop_get_slot,':player_town','trp_player',slot_player_town),
			(store_troop_faction,':daimyo_faction','$g_conversation_troop'),
			(faction_get_slot,':enemy_faction',':daimyo_faction',slot_faction_enemy_faction),
			(str_store_faction_name,s12,':daimyo_faction'),
			(str_store_faction_name,s13,':enemy_faction'),
			(str_store_troop_name,s14,':player_lord'),
			(str_store_party_name,s15,':player_town'),
			(str_store_string,s10,'@The battle with the {s13} is persistant and brutal.'),
			(str_store_string,s10,'@{s10} Find them wherever they hide and crush them beneath your {s12} heel.'),
			(str_store_string,s10,'@{s10} By {s12} law, you have full right of conquest, and will share in our inevitable victory.'),
			(str_store_string,s10,'@{s10} Besides taking what you can from their thieving fingers, I may have specific tasks for you, depending on how the war tilts.'),
			(str_store_string,s10,'@{s10} These missions will be vital to the {s12} war effort, so carry them out with devotion and loyalty, and the rank and privilege of the {s12} will open its doors to you.'),
			(str_store_string,s10,'@{s10} As my retainer, you will be expected to maintain your own private army, in addition to any troops that I provide you, and that as your power and influence grows, so must the size of your army.'),
			(str_store_string,s10,'@{s10} Now, report to {s14} of {s15}. He is your commander and will assign any missions you might be given.'),
			(str_store_string,s10,'@{s10} May victory grace our armies and the blood of {s13} stain the field.'),
			],
		"{s10}","close_window",
		[
			(store_troop_faction,':daimyo_faction','$g_conversation_troop'),
			(faction_get_slot,':faction_letter',':daimyo_faction',slot_faction_letter),
			(player_has_item,':faction_letter'),
			(troop_remove_item,'trp_player',':faction_letter'),
			]],
    [anyone,"swear_denied",[],"Perhaps you are not as brave as I thought.","close_window",[]],
    [anyone,"start",
		[
			(store_conversation_troop,'$g_conversation_troop'),
			(this_or_next|eq,'$g_conversation_troop','trp_hosokawa_katsumoto'),
			(eq,'$g_conversation_troop','trp_yamana_souzen'),
			(store_troop_faction,':daimyo_faction','$g_conversation_troop'),
			(faction_get_slot,':enemy_faction',':daimyo_faction',slot_faction_enemy_faction),
			(faction_get_slot,':faction_quest_letter',':daimyo_faction',slot_faction_letter),
			(faction_slot_eq,':enemy_faction',slot_faction_joined,false),
			(neg|player_has_item,':faction_quest_letter'),
			],
     "How dare you appear before me uninvited! Leave me!","close_window",[]],
    [trp_hosokawa_katsumoto,"start",
		[
			(store_conversation_troop,'$g_conversation_troop'),
			(this_or_next|eq,'$g_conversation_troop','trp_hosokawa_katsumoto'),
			(eq,'$g_conversation_troop','trp_yamana_souzen'),
			(store_troop_faction,':daimyo_faction','$g_conversation_troop'),
			(faction_get_slot,':enemy_faction',':daimyo_faction',slot_faction_enemy_faction),
			(faction_get_slot,':faction_quest_letter',':daimyo_faction',slot_faction_letter),
			(faction_slot_eq,':enemy_faction',slot_faction_joined,false),
			(neg|player_has_item,':faction_quest_letter'),
			(str_store_faction_name,s12,':enemy_faction'),
			],
     "How dare you appear before me, {s12} scum! Leave me!","close_window",[]],
    
# fishmonger dialogs
	[anyone,'start',
		[
			(store_conversation_troop,'$g_conversation_troop'),
			(is_between,'$g_conversation_troop',fishmongers_begin,fishmongers_end),
			],
		'Hello, {Tono/Hime}...','fm_pre_talk',[]],
	[anyone,'fm_pre_talk',[],'How can I help you?','fm_talk_1',[]],
	[anyone|plyr,'fm_talk_1',[],"I'd like to look at your goods",'fm_buy',[]],
	[anyone,'fm_buy',[],'Of course. Please look around.','fm_pre_talk',[(change_screen_trade)]],
	[anyone|plyr,'fm_talk_1',[],"Never mind. Good day.",'fm_end',[]],
	[anyone,'fm_end',[],'Of course. Good day.','close_window',[]],
# begin sake merchant/broker dialogs
	[anyone,'start',
		[
			(store_conversation_troop,'$g_conversation_troop'),
			(is_between,'$g_conversation_troop',shoen_brokers_begin,shoen_brokers_end),
			],
		"Welcome, {Tono/Hime}...",'broker_pre_talk',[]],
	[anyone,'broker_pre_talk',[],'How can I help you today?','broker_talk_1',[]],
	[anyone|plyr,'broker_talk_1',[],"I'd like to have a look at your wares.",'broker_buy_goods',[]],
	[anyone,'broker_buy_goods',[],'Of course. Have a look around.','broker_pre_talk',[(change_screen_trade)]],
	[anyone|plyr,'broker_talk_1',[],"I'm looking to make an investment",'broker_start_investment',[]],
	[anyone,'broker_start_investment',
		[
			(call_script,'script_cf_broker_has_available_investments','$g_conversation_troop'),
			],
			'Which shoen would you like to see?','broker_see_shoen',[]],
	[anyone,'broker_start_investment',[],'I apologize, {Tono/Hime}, but I have nothing available at the moment','close_window',[]],
	[anyone|repeat_for_parties|plyr,'broker_see_shoen',
		[
			(store_repeat_object,':shoen'),
			(call_script,'script_cf_party_is_of_template',':shoen','pt_shoen'),
			(party_slot_eq,':shoen',slot_shoen_broker,'$g_conversation_troop'),
			(party_get_slot,':shoen_town',':shoen',slot_shoen_town),
			(str_store_party_name,10,':shoen_town'),
			(str_store_string,11,'@Shoen near {s10}'),
			],
		'{s11}','broker_talk_shoen_prospectus',[(store_repeat_object,'$selected_shoen')]],
	[anyone,'broker_talk_shoen_prospectus',[],'{s11}','broker_talk_shoen_actions',
		[
			(party_get_slot,reg10,'$selected_shoen',slot_shoen_share_price),
			(party_get_slot,reg11,'$selected_shoen',slot_shoen_outstanding_shares),
			(party_get_slot,reg12,'$selected_shoen',slot_shoen_share_price_moving_avg),
			(party_get_slot,reg13,'$selected_shoen',slot_shoen_dividend),
			(str_store_string,s11,"@{s10}^Share price: {reg10}^Outstanding shares: {reg11}^Price 10-day average: {reg12}^Current dividend: {reg13}"),
			]
		],
	[anyone|plyr,'broker_see_shoen',[],'Never mind','broker_talk_end',[]],
	[anyone|plyr,'broker_talk_1',
		[
			(call_script,'script_cf_troop_owns_broker_shoen_shares','$g_conversation_troop','trp_player'),
			],
		"I'd like to check on my investments.",'broker_talk_get_status',[]],
	[anyone,'broker_talk_get_status',[],'Which shoen would you like an update on?','broker_talk_select_status',[]],
	[anyone|repeat_for_parties|plyr,'broker_talk_select_status',
		[
			(store_repeat_object,':shoen'),
			(call_script,'script_cf_party_is_of_template',':shoen','pt_shoen'),
			(party_slot_eq,':shoen',slot_shoen_broker,'$g_conversation_troop'),
			(call_script,'script_cf_troop_owns_shares_of_shoen','trp_player',':shoen'),
			(party_get_slot,':shoen_town',':shoen',slot_shoen_town),
			(str_store_party_name,10,':shoen_town'),
			(str_store_string,10,'@{s10} shoen'),
			],
		'{s10}','broker_talk_shoen_update',[(store_repeat_object,'$selected_shoen')]],
	[anyone,'broker_talk_shoen_update',[],'{s11}','broker_talk_shoen_actions',
		[
			(party_get_slot,reg10,'$selected_shoen',slot_shoen_share_price),
			(party_get_slot,reg11,'$selected_shoen',slot_shoen_outstanding_shares),
			(party_get_slot,reg12,'$selected_shoen',slot_shoen_share_price_moving_avg),
			(party_get_slot,reg13,'$selected_shoen',slot_shoen_labor_moving_avg),
			(call_script,'script_cf_shoen_get_shareholder_slot','$selected_shoen','trp_player'),
			(assign,':shareholder_index',reg0),
			(party_get_slot,':shares_owned_array','$selected_shoen',slot_shoen_shareholders_shares_owned_array),
			(party_get_slot,':accumulated_dividends_array','$selected_shoen',slot_shoen_shareholders_accumulated_dividends_array),
			(party_get_slot,':dca_value_array','$selected_shoen',slot_shoen_shareholders_dca_value_array),
			(call_script,'script_array_peek',':shares_owned_array',':shareholder_index'),
			(assign,reg14,'$return'),
			(call_script,'script_array_peek',':accumulated_dividends_array',':shareholder_index'),
			(assign,reg15,'$return'),
			(call_script,'script_array_peek',':dca_value_array',':shareholder_index'),
			(assign,reg16,'$return'),
			(str_store_string,11,"@{s10}^Share price: {reg10}^Outstanding shares: {reg11}^Price 10-day average: {reg12}^No. shares owned: {reg14}^Accumulated dividends: {reg15}^Share mon cost average: {reg16}"),
			]],
	[anyone,'broker_talk_shoen_actions',[],'Would you like to take any action on this shoen?','broker_talk_select_action',[]],
	[anyone|plyr,'broker_talk_select_action',
		[
			(assign,':dialog_valid',false),
			(try_begin),
				(call_script,'script_cf_troop_owns_shares_of_shoen','trp_player','$selected_shoen'),
			(else_try),
				(assign,':dialog_valid',true),
			(try_end),
			(eq,':dialog_valid',true),
			],
		'I would like see the prospectus.','broker_talk_shoen_prospectus',[]],
	[anyone|plyr,'broker_talk_select_action',
		[
			(call_script,'script_cf_troop_owns_shares_of_shoen','trp_player','$selected_shoen'),
			],
		'I would like an account update.','broker_talk_shoen_update',[]],
	[anyone|plyr,'broker_talk_select_action',
		[
			(party_slot_ge,'$selected_shoen',slot_shoen_outstanding_shares,10),
			],
		'I would like to buy some shares.','broker_buy_shares',[]],
	[anyone,'broker_buy_shares',[],'How many would you like to buy?','broker_select_buy_amount',[]],
	[anyone|repeat_for_parties|plyr,'broker_select_buy_amount',
		[	
			(store_repeat_object,':party_no'),
			(this_or_next|eq,':party_no',10),
			(this_or_next|eq,':party_no',20),
			(this_or_next|eq,':party_no',50),
			(eq,':party_no',100),
			(assign,reg10,':party_no'),
			],
		'{reg10} shares','broker_confirm_buy_amount',[(store_repeat_object,'$shoen_shares_buy_amount')]],
	[anyone|plyr,'broker_select_buy_amount',[],'All','broker_confirm_buy_amount',
		[
			(party_get_slot,'$shoen_shares_buy_amount','$selected_shoen',slot_shoen_outstanding_shares),
			],
		],
	[anyone|plyr,'broker_select_buy_amount',[],'None','broker_cancel_buy',[]],
	[anyone,'broker_cancel_buy',[],'Very well, the transaction has been canceled.','broker_talk_shoen_actions',[]],
	[anyone,'broker_confirm_buy_amount',
		[
			(party_slot_ge,'$selected_shoen',slot_shoen_outstanding_shares,'$shoen_shares_buy_amount'),
			],
		'{s11}','broker_player_confirm_buy_amount',
		[
			(party_get_slot,':shoen_town','$selected_shoen',slot_shoen_town),
			(party_get_slot,':current_share_price','$selected_shoen',slot_shoen_share_price),
			(store_mul,'$total_share_purchase_price',':current_share_price','$shoen_shares_buy_amount'),
			(assign,reg10,'$shoen_shares_buy_amount'),
			(assign,reg11,':current_share_price'),
			(assign,reg12,'$total_share_purchase_price'),
			(str_store_party_name,s11,':shoen_town'),
			(str_store_string,s11,'@To confirm: you are buying {reg10} shares of the {s11} shoen at {reg11} mon per share, for a total of {reg12} mon.'),
			],
		],
	[anyone|plyr,'broker_player_confirm_buy_amount',
		[
			(store_troop_gold,':current_cash','trp_player'),
			(ge,':current_cash','$total_share_purchase_price'),
			],
		'Yes.','broker_player_purchase_shares',
		[
			(troop_remove_gold,'trp_player','$total_share_purchase_price'),
			(call_script,'script_shoen_transact_shares','$selected_shoen','trp_player',shoen_buy_shares,'$shoen_shares_buy_amount'),
			]
		],
	[anyone,'broker_player_purchase_shares',[],'Excellent. The transaction has been recorded.','broker_talk_shoen_actions',[]],
	[anyone|plyr,'broker_player_confirm_buy_amount',[],'No.','broker_cancel_buy',[]],
	[anyone|plyr,'broker_talk_select_action',
		[
			(call_script,'script_cf_troop_owns_shares_of_shoen','trp_player','$selected_shoen',false),
			],
		'I would like to sell some shares.','broker_sell_shares',[]],
	[anyone,'broker_sell_shares',[],'How many would you like to sell?','broker_select_sell_amount',[]],
	[anyone|repeat_for_parties|plyr,'broker_select_sell_amount',
		[
			(store_repeat_object,':party_no'),
			(this_or_next|eq,':party_no',10),
			(this_or_next|eq,':party_no',20),
			(this_or_next|eq,':party_no',50),
			(eq,':party_no',100),
			(party_get_slot,':shares_owned_array','$selected_shoen',slot_shoen_shareholders_shares_owned_array),
			(call_script,'script_cf_shoen_get_shareholder_slot','$selected_shoen','trp_player'),
			(neq,reg0,null),
			(call_script,'script_array_peek',':shares_owned_array',reg0),
			(ge,'$return',':party_no'),
			(assign,reg10,':party_no'),
			],
		'{reg10} shares','broker_confirm_sell_amount',[(store_repeat_object,'$shoen_shares_sell_amount')]],
	[anyone|plyr,'broker_select_sell_amount',[],'All','broker_confirm_sell_amount',
		[
			(call_script,'script_cf_shoen_get_shareholder_slot','$selected_shoen','trp_player'),
			(neq,reg0,null),
			(assign,':shareholder_index',reg0),
			(party_get_slot,':shares_owned_array','$selected_shoen',slot_shoen_shareholders_shares_owned_array),
			(call_script,'script_array_peek',':shares_owned_array',':shareholder_index'),
			(assign,'$shoen_shares_sell_amount','$return'),
			],
		],
	[anyone,'broker_confirm_sell_amount',
		[
			],
		'{s11}','broker_player_confirm_sell_amount',
		[
			(party_get_slot,':shoen_town','$selected_shoen',slot_shoen_town),
			(party_get_slot,':current_share_price','$selected_shoen',slot_shoen_share_price),
			(store_mul,'$total_share_selling_price',':current_share_price','$shoen_shares_sell_amount'),
			(assign,reg10,'$shoen_shares_sell_amount'),
			(assign,reg11,':current_share_price'),
			(assign,reg12,'$total_share_selling_price'),
			(str_store_party_name,s11,':shoen_town'),
			(str_store_string,s11,'@To confirm: you are selling {reg10} shares of the {s11} shoen at {reg11} mon per share, for a total of {reg12} mon.'),
			],
		],
	[anyone|plyr,'broker_player_confirm_sell_amount',
		[
			# (call_script,'script_cf_shoen_get_shareholder_slot','$selected_shoen','trp_player'),
			# (assign,':shareholder_slot',reg0),
			# (store_add,':shareholder_shares_owned_slot',':shareholder_slot',num_shareholders),
			# (party_slot_ge,'$selected_shoen',':shareholder_shares_owned_slot','$shoen_shares_sell_amount'),
			],
		'Yes.','broker_player_sell_shares',
		[
			(call_script,'script_shoen_transact_shares','$selected_shoen','trp_player',shoen_sell_shares,'$shoen_shares_sell_amount'),
			(troop_add_gold,'trp_player','$total_share_purchase_price'),
			]
		],
	[anyone,'broker_player_sell_shares',[],'Excellent. The transaction has been recorded.','broker_talk_shoen_actions',[]],
	[anyone|plyr,'broker_player_confirm_sell_amount',[],'No.','broker_cancel_buy',[]],
	[anyone|plyr,'broker_talk_select_action',[],'I would like to collect my dividends.','broker_collect_dividends',[]],
	[anyone,'broker_collect_dividends',
		[
			(call_script,'script_cf_shoen_get_shareholder_slot','$selected_shoen','trp_player'),
			(assign,':shareholder_slot',reg0),
			(party_get_slot,':accumulated_dividends_array','$selected_shoen',slot_shoen_shareholders_accumulated_dividends_array),
			(party_get_slot,':accumulated_dividends',':accumulated_dividends_array',':shareholder_slot'),
			(gt,':accumulated_dividends',0),
			(assign,reg12,':accumulated_dividends'),
			],
		'{reg12} mon have been transfered to you.','broker_talk_select_action',
		[
			(troop_add_gold,'trp_player',reg12),
			(call_script,'script_cf_shoen_get_shareholder_slot','$selected_shoen','trp_player'),
			(assign,':shareholder_slot',reg0),
			(party_get_slot,':accumulated_dividends_array','$selected_shoen',slot_shoen_shareholders_accumulated_dividends_array),
			(party_set_slot,':accumulated_dividends_array',':shareholder_slot',0),
			]],
	[anyone,'broker_collect_dividends',[],'You have no accumulated dividends.','broker_talk_select_action',[]],
	[anyone|plyr,'broker_talk_select_action',
		[
			(call_script,'script_cf_troop_is_shoen_majority_shareholder','trp_player','$selected_shoen'),
			],
		'I would like to make improvements to the shoen.','broker_make_improvements',[]],
	[anyone|plyr,'broker_talk_select_action',[],'No, thank you.','broker_pre_talk',[]],
	[anyone,'broker_make_improvements',
		[
			(call_script,'script_cf_troop_is_shoen_majority_shareholder','trp_player','$selected_shoen'),
			],
		'You are the majority shareholder, but no improvements can be made yet.','close_window',[]],
	[anyone,'broker_make_improvements',[],"I'm sorry, but you do not have the authority to make any improvements.",'close_window',[]],
	[anyone|plyr,'broker_talk_1',[],'Nothing. Have a good day.','broker_talk_end',[]],
	[anyone,'broker_talk_end',[],'And also to you.','close_window',[]],
# begin outfitter dialogs
	# [anyone,'start',
		# [
			# (store_conversation_troop,'$g_conversation_troop'),
			# (is_between,'$g_conversation_troop',outfitters_begin,outfitters_end),
			# ],
		# 'Hello, {Tono/Hime}. Who would you like to outfit?','outfit_start',[]],
	# [anyone|plyr|repeat_for_troops,'outfit_start',
		# [
			# (store_repeat_object,':troop_id'),
			# (this_or_next|is_between,':troop_id',samurai_start,samurai_end),
			# (is_between,':troop_id',armed_peasants_begin,armed_peasants_end),
			
			# (str_store_troop_name,s11,':troop_id'),
			# ],
		# '{s10}','
#Begin merchant dialogs
    [anyone,"start",
		[
			(store_conversation_troop,'$g_conversation_troop'),
			(is_between,'$g_conversation_troop',merchants_begin,merchants_end),
			],
     "Greetings, {Tono/Hime}...","merchant_talk_1",[]],
    [anyone,"merchant_talk_1",[],"What can I do for you?","merchant_talk_2",[]],
	[anyone|plyr,'merchant_talk_2',
		[
			(assign,':dialog_active',false),
			(try_begin),
				(check_quest_active,'qst_merchant_deliver_shipment'),
				(assign,'$g_selected_quest','qst_merchant_deliver_shipment'),
				(quest_slot_eq,'$g_selected_quest',slot_quest_target_troop,'$g_conversation_troop'),
				(assign,':dialog_active',true),
				(quest_get_slot,':quest_item','$g_selected_quest',slot_quest_item_1),
				(quest_get_slot,':quest_item_cnt','$g_selected_quest',slot_quest_item_1_cnt),
				(str_store_item_name,s11,':quest_item'),
				(assign,reg10,':quest_item_cnt'),
				(str_store_string,s10,'@I am here to deliver {reg10} {s11}'),
			(else_try),
			(try_end),
			(eq,':dialog_active',true),				
			],
		'{s10}','merchant_quest_target_troop',
		[
			(try_begin),
				(eq,'$g_selected_quest','qst_merchant_deliver_shipment'),
				(quest_get_slot,':quest_item','$g_selected_quest',slot_quest_item_1),
				(store_item_kind_count,':quest_item_cnt',':quest_item','trp_player'),
				(troop_remove_items,'trp_player',':quest_item',':quest_item_cnt'),
				(add_xp_as_reward,reg0),
				(assign,'$g_talk_context',tc_merchant_deliver_shipment),
			(else_try),
			(try_end),
			]],
	[anyone,'merchant_quest_target_troop',
		[
			(try_begin),
				(eq,'$g_talk_context',tc_merchant_deliver_shipment),
				(str_store_string,s10,'@Thanks for the delivery. I hope your reward is sufficient'),
			(else_try),
			(try_end),
			],
		'{s10}','merchant_talk_2',
		[
			(try_begin),
				(eq,'$g_selected_quest','qst_merchant_deliver_shipment'),
				(troop_add_items,'trp_player','itm_string_of_coins',5),
				(quest_get_slot,':quest_giver','$g_selected_quest',slot_quest_giver),
				(call_script,'script_object_modify_slot',obj_troop,':quest_giver',slot_troop_quest_active,op_asn,false),
			(else_try),
			(try_end),
			(call_script,'script_end_quest','$g_selected_quest'),
			]],
    [anyone|plyr,"merchant_talk_2",
		[
			(check_quest_active,"qst_merchant_intro_letter"),
			(quest_set_slot,'qst_merchant_intro_letter',slot_quest_target_troop,'$g_conversation_troop'),
			],
     "The merchant in Hyogo sent me.","begin_merchant_quest_1",[]],
    [anyone|plyr,"merchant_talk_2",
		[
			(eq,'$g_conversation_troop',"trp_city_8_merchant"),
			(check_quest_active,'qst_merchant_sell_tea'),
			],
     "About the job you gave me...","merchant_quest_1_progress",[]],
    [anyone|plyr,"merchant_talk_2",
		[
			(eq,'$g_conversation_troop',"trp_city_5_merchant"),
			(check_quest_active,'qst_merchant_sell_tea'),
			],
     "I'd like to sell some tea.","merchant_quest_sell_goods",[]],
    [anyone|plyr,"merchant_talk_2",
		[
			(eq,'$g_conversation_troop',"trp_city_6_merchant"),
			(check_quest_active,'qst_merchant_sell_tea'),
			],
     "I'd like to sell some tea.","merchant_quest_sell_goods",[]],
    [anyone|plyr,"merchant_talk_2",[],"I'd like to see your wares.","merchant_goods",[]],
    [anyone|plyr,'merchant_talk_2',
		[
			(check_quest_active,'qst_merchant_salt_za_1'),
			(neg|check_quest_concluded,'qst_merchant_salt_za_1'),
			(quest_slot_eq,'qst_merchant_salt_za_1',slot_quest_target_troop,'$g_conversation_troop'),
			],
		'I was told to speak with you about some salt.','salt_za_pickup_salt',[]],
    [anyone,"salt_za_pickup_salt",[],"Ah, I was told you'd be coming. Here's the salt.","close_window",
		[
	        (troop_add_items,"trp_player","itm_salt",6),
	        (set_spawn_radius,20),
	        (spawn_around_party,"p_main_party","pt_bandits"),
	        (party_set_ai_behavior,reg0,ai_bhvr_travel_to_party),
	        (party_set_ai_object,reg0,"p_main_party"),
			(party_set_slot,reg0,slot_spawn_att_to_player,att_hostile),
			]],
	[anyone|plyr,'merchant_talk_2',
		[	
			(check_quest_active,"qst_merchant_salt_za_1"),
			(neg|check_quest_concluded,'qst_merchant_salt_za_1'),
			(eq,'$g_conversation_troop',"trp_village_22_merchant"),
			(store_item_kind_count,reg2,'itm_salt',"trp_player"),
			(ge,reg2,6),         
			],
		'I am here to deliver some salt.','salt_za_deliver_salt',
		[
			 (troop_remove_items,"trp_player","itm_salt",6),
			 (val_mul,reg0,2),
			 (assign,"$salt_fee",reg0),
			 (troop_add_gold,"trp_player",reg0),
			 (call_script,'script_conclude_quest','qst_merchant_salt_za_1'),
			]],
	[anyone,"salt_za_deliver_salt",[],
	"Excellent! The salt shipment is here. I was beginning to get worried. And, here is the payment. Now, head back to Nara and speak with the merchant.","close_window",[]],
    [anyone|plyr,'merchant_talk_2',
		[
			(check_quest_active,'qst_merchant_salt_za_1'),
			(check_quest_concluded,'qst_merchant_salt_za_1'),
			(eq,'$g_conversation_troop','trp_city_12_merchant'),
			],
		'I have delivered the salt.','salt_za_a2',[]],
	[anyone,"salt_za_a2",
		[
			(store_troop_gold,reg1,"trp_player"),
			(ge,reg1,"$salt_fee"),
			],
     "More importantly, you have my money. You've done well. I hereby make you a member of the Yamato salt za.","salt_za_a3",
		[
			(troop_remove_gold,"trp_player","$salt_fee"),
			(troop_add_gold,"trp_player",100),
			(add_xp_as_reward,250),
			(call_script,'script_object_modify_slot',obj_quest,'qst_faction_enza',slot_quest_za_master,op_asn,'trp_city_12_merchant'),
			(call_script,'script_object_modify_slot',obj_quest,'qst_faction_enza',slot_quest_za_player_standing,op_asn,0),
			(call_script,'script_object_modify_slot',obj_troop,'trp_city_12_merchant',slot_troop_quest_active,op_asn,false),
			(call_script,'script_end_quest','qst_merchant_salt_za_1'),
			(call_script,'script_start_quest','qst_faction_enza'),
			]],
    [anyone|plyr,"salt_za_a3",[],"I am honored.","salt_za_a4",[]],
    [anyone,"salt_za_a4",[],"Stop by every now and then, as I'll have various jobs for you.","close_window",[]],
    [anyone,"salt_za_a2",
		[
			(store_troop_gold,reg1,"trp_player"),
			(lt,reg1,"$salt_fee"),
			],
     "Where's my money, damn it! You've crossed the wrong za, pal.","close_window",
		[
	        (store_current_scene,reg10),
	        (modify_visitors_at_site,reg10),
	        (reset_visitors),
	        (set_visitor,1,"trp_player"),
	        (set_visitor,2,"trp_naginata_souhei_j"),
	        (set_visitor,3,"trp_naginata_souhei_j"),
	        (set_visitor,4,"trp_naginata_souhei_j"),
	        (set_party_battle_mode),
	        (set_jump_mission,"mt_single_combat"),
	        (jump_to_scene,reg10),
	        (change_screen_mission,0),
			]],
	[anyone|plyr,'merchant_talk_2',
		[
			(check_quest_active,'qst_faction_enza'),
			(quest_get_slot,':za_master','qst_faction_enza',slot_quest_za_master),
			(eq,'$g_conversation_troop',':za_master'),
			(troop_slot_eq,':za_master',slot_troop_quest_active,false),
			],
		'Do you have any jobs for me?','za_assign_quest',
		[
			(assign,'$g_selected_quest',null),
			(call_script,'script_get_class_quest'),
			(this_or_next|eq,reg0,'qst_merchant_patrol_trade_route'),
			(this_or_next|eq,reg0,'qst_merchant_establish_trading_post'),
			(this_or_next|eq,reg0,'qst_merchant_negotiate_trade_contract'),
			(eq,reg0,'qst_merchant_deliver_shipment'),
			(assign,'$g_selected_quest',reg0),
			]],
	[anyone,'za_assign_quest',
		[
			(neq,'$g_selected_quest',null),
			],
		'Actually, I do have something...','za_quest_details',[]],
	[anyone,'za_quest_details',[],'{s10}','za_quest_accept',
		[
			(call_script,'script_merchant_quest_accept','$g_selected_quest'),
			(str_clear,s10),
			(try_begin),
				(eq,'$g_selected_quest','qst_merchant_patrol_trade_route'),
				(quest_get_slot,':target_city_1','qst_merchant_patrol_trade_route',slot_quest_party_1),
				(quest_get_slot,':target_city_2','qst_merchant_patrol_trade_route',slot_quest_party_2),
				(str_store_party_name,s11,':target_city_1'),
				(str_store_party_name,s12,':target_city_2'),
				(str_store_string,s10,"@The trade route between {s11} and {s12} has been harassed by bandits recently. One group in particular is led by the scoundrel running this particular show. Eliminate them, or better yet, bring this man in and we'll deal with him"),
				(str_store_troop_name,s13,'$g_conversation_troop'),
				(setup_quest_giver,'qst_merchant_patrol_trade_route',s13),
				(setup_quest_text,'qst_merchant_patrol_trade_route'),
			(else_try),
				(eq,'$g_selected_quest','qst_merchant_deliver_shipment'),
				(quest_get_slot,':item_no','qst_merchant_deliver_shipment',slot_quest_item_1),
				(quest_get_slot,':target_party','qst_merchant_deliver_shipment',slot_quest_target_party),
				(quest_get_slot,':target_troop','qst_merchant_deliver_shipment',slot_quest_target_troop),
				(quest_get_slot,reg10,'qst_merchant_deliver_shipment',slot_quest_time_to_completion),
				(str_store_item_name,s11,':item_no'),
				(str_store_party_name,s12,':target_party'),
				(str_store_troop_name,s13,':target_troop'),
				(str_store_string,s10,"@Deliver this load of {s11} to {s13} in {s12} within {reg10} days. I'm counting on you. Don't screw it up."),
			(else_try),
				(eq,'$g_selected_quest','qst_merchant_establish_trading_post'),
				(quest_get_slot,':target_party','qst_merchant_establish_trading_post',slot_quest_target_party),
				(quest_get_slot,':target_troop','qst_merchant_establish_trading_post',slot_quest_target_troop),
				(str_store_party_name,s11,':target_party'),
				(str_store_troop_name,s10,':target_troop'),
				(str_store_string,s10,"@Go speak with {s10}, the kokujin of {s11}, and negotiate a new trading post with him. I'm counting on you. Don't screw it up."),
			(else_try),
				(eq,'$g_selected_quest','qst_merchant_negotiate_trade_contract'),
				(quest_get_slot,':target_party','qst_merchant_establish_trading_post',slot_quest_target_party),
				(quest_get_slot,':target_troop','qst_merchant_establish_trading_post',slot_quest_target_troop),
				(str_store_party_name,s11,':target_party'),
				(str_store_troop_name,s10,':target_troop'),
				(str_store_string,s10,"@Go speak with {s10}, the kokujin of {s11}, and negotiate a new trade contract with him. I'm counting on you. Don't screw it up."),
			(try_end),
			(quest_set_slot,'$g_selected_quest',slot_quest_giver,'$g_conversation_troop'),
			(troop_set_slot,'$g_conversation_troop',slot_troop_quest,'$g_selected_quest'),
			(troop_set_slot,'$g_conversation_troop',slot_troop_quest_active,true),
			(call_script,'script_start_quest','$g_selected_quest'),
			]
		],
	[anyone|plyr,'za_quest_accept',[],"Very well. I'll be going then",'za_quest_end',[]],
	[anyone,'za_quest_end',[],"Good. Don't fail",'close_window',[]],
	[anyone,'za_assign_quest',
		[
			(eq,'$g_selected_quest',null),
			],
		'None right now. Come back later','merchant_talk_2',[]],
	[anyone|plyr,'merchant_talk_2',
		[
			(check_quest_active,'qst_faction_enza'),
			(quest_slot_eq,'qst_faction_enza',slot_quest_za_master,'$g_conversation_troop'),
			(troop_slot_eq,'$g_conversation_troop',slot_troop_quest_active,true),
			],
		'About that job you gave me...','za_quest_status',
		[
			(troop_get_slot,'$g_selected_quest','$g_conversation_troop',slot_troop_quest),
			]],
	[anyone,'za_quest_status',[],'Yes? What about it?','za_quest_status_2',[(assign,'$g_talk_context',null)]],
	[anyone|plyr,'za_quest_status_2',
		[
			(str_clear,s10),
			(try_begin),
				(eq,'$g_selected_quest','qst_merchant_patrol_trade_route'),
				(try_begin),
					(check_quest_succeeded,'qst_merchant_patrol_trade_route'),
					(main_party_has_troop,'trp_bandit_leader'),
					(str_store_string,s10,'@I have finished my patrol duties, and have brought in the bandit responsible for this mess.'),
					(assign,'$g_talk_context',tc_quest_succeeded),
				(else_try),
					(check_quest_succeeded,'qst_merchant_patrol_trade_route'),
					(str_store_string,s10,'@I have finished my patrol duties. The bandits are no more.'),
					(assign,'$g_talk_context',tc_quest_succeeded),
				(else_try),
					(check_quest_failed,'qst_merchant_patrol_trade_route'),
					(str_store_string,s10,'@I have finished my patrol duties, but unfortunately the bandits are still out there.'),
					(assign,'$g_talk_context',tc_quest_failed),
				(try_end),
			(else_try),
				(eq,'$g_selected_quest','qst_merchant_deliver_shipment'),
				(try_begin),
					(check_quest_succeeded,'qst_merchant_deliver_shipment'),
					(str_store_string,s10,'@The delivery has been made. Here is the payment.'),
					(assign,'$g_talk_context',tc_quest_succeeded),
				(else_try),
					(check_quest_failed,'qst_merchant_deliver_shipment'),
					(str_store_string,s10,'@I did not make the delivery in time.'),
					(assign,'$g_talk_context',tc_quest_failed),
				(try_end),
			(else_try),
				(eq,'$g_selected_quest','qst_merchant_establish_trading_post'),
				(try_begin),
					(check_quest_succeeded,'qst_merchant_establish_trading_post'),
					(str_store_string,s10,'@I have negotiated a new trading post with the following terms.'),
					(assign,'$g_talk_context',tc_quest_succeeded),
				(else_try),
					(check_quest_failed,'qst_merchant_establish_trading_post'),
					(str_store_string,s10,'@I was unable to open the trading post.'),
					(assign,'$g_talk_context',tc_quest_failed),
				(try_end),
			(else_try),
				(eq,'$g_selected_quest','qst_merchant_negotiate_trade_contract'),
				(try_begin),
					(check_quest_succeeded,'qst_merchant_deliver_shipment'),
					(str_store_string,s10,'@I have negotiated a new trade contract with the following terms.'),
					(assign,'$g_talk_context',tc_quest_succeeded),
				(else_try),
					(check_quest_failed,'qst_merchant_deliver_shipment'),
					(str_store_string,s10,'@I was unable to secure a trade contract.'),
					(assign,'$g_talk_context',tc_quest_failed),
				(try_end),
			(try_end),
			],
		'{s10}','za_quest_complete',[]],
	[anyone,'za_quest_complete',
		[
			(eq,'$g_talk_context',tc_quest_succeeded),
			(store_random_in_range,reg10,0,3),
			(try_begin),
				(eq,reg10,0),
				(str_store_string,s11,"@Keep this up, and you'll go far in this za."),
			(else_try),
				(eq,reg10,1),
				(str_store_string,s11,"@My trust was well placed."),
			(else_try),
				(eq,reg10,2),
				(str_store_string,s11,"@Success brings ever greater profits."),
			(try_end),
			],
		"Excellent work. {s11}",'za_quest_close',
		[
			(call_script,'script_merchant_quest_reward','$g_selected_quest'),
			(call_script,'script_end_quest','$g_selected_quest'),
			]],
	[anyone,'za_quest_complete',
		[
			(eq,'$g_talk_context',tc_quest_failed),
			],
		"This is unfortunate. I expected more from you.",'za_quest_close',
		[
			(call_script,'script_merchant_quest_abort','$g_selected_quest'),
			(call_script,'script_end_quest','$g_selected_quest'),
			]],
	[anyone|plyr,'za_quest_close',
		[
			(str_clear,s10),
			(try_begin),
				(eq,'$g_talk_context',tc_quest_succeeded),
				(str_store_troop_name,s11,'$g_conversation_troop'),
				(str_store_string,s10,'@My thanks to you, {s11}'),
			(else_try),
				(eq,'$g_talk_context',tc_quest_failed),
				(str_store_troop_name,s11,'$g_conversation_troop'),
				(str_store_string,s10,'@My apologies, {s11}'),
			(try_end),
			],
		'{s10}','za_quest_finish',[]],
	[anyone,'za_quest_finish',
		[
			(str_clear,s10),
			(try_begin),
				(eq,'$g_talk_context',tc_quest_succeeded),
				(str_store_string,s10,'@And to you, {playername}. Good day'),
			(else_try),
				(eq,'$g_talk_context',tc_quest_failed),
				(str_store_troop_name,s11,'$g_conversation_troop'),
				(str_store_string,s10,'@Indeed. I hope your future performance improves.'),
			(try_end),
			],
		'{s10}','close_window',[]],
	[anyone|plyr,'za_quest_status_2',[],"I haven't finished it yet.",'za_quest_incomplete',[]],
	[anyone,'za_quest_incomplete',[],'Well get to it. Time is money.','close_window',[]],
    [anyone|plyr,'za_quest_status_2',[],"I am unable to finish it.",'za_quest_abort',[]],
	[anyone,'za_quest_abort',[],'Very well, but this will harm your reputation.','close_window',
		[
			(call_script,'script_merchant_quest_abort','$g_selected_quest'),
			(call_script,'script_end_quest','$g_selected_quest'),
			 ]],
    [anyone|plyr,"merchant_talk_2",[],"What are the locals saying?","merchant_gossip_1",[]],
	[anyone|plyr,'merchant_talk_2',
		[
			(check_quest_active,'qst_ronin_investigate_bandit_activity'),
			(quest_slot_eq,'qst_ronin_investigate_bandit_activity',slot_quest_party_1,'$g_encountered_party'),
			],
		"I'm looking to some bandits seen near here. Have you heard anything?",'investigation_merchant_1',[]],
	[anyone,'investigation_merchant_1',
		[
			(call_script,'script_cf_object_flag_set',obj_quest,'qst_ronin_investigate_bandit_activity',slot_quest_flags,riqf_merchant),
			(quest_get_slot,reg20,'qst_ronin_investigate_bandit_activity',slot_quest_flags),
			(display_message,'@Flag value: {reg20}',purple_text),
			# (call_script,'script_get_flag_bit',reg20,2),
			# (eq,reg0,1),
			],
		"Yeah, I've seen them. Came in here not two days ago, wanting some horses and supplies. Not the sort of people I'd want to meet at night, if you catch my meaning.",
		'investigation_complete',
		[
			(call_script,'script_object_set_flag',obj_quest,'qst_ronin_investigate_bandit_activity',slot_quest_flags,riqf_innkeeper,true),
			# (call_script,'script_set_flag_bit',reg20,3,1),
			# (quest_set_slot,'qst_ronin_investigate_bandit_activity',slot_quest_flags,reg0),
			]],
	[anyone,'investigation_merchant_1',
		[
			(store_attribute_level,':chr_level','trp_player',ca_charisma),
			(val_div,':chr_level',2),
			(store_random_in_range,':roll',0,10),
			# (display_message,'@{reg1} / 10',purple_text),
			(le,':roll',':chr_level'),
			],
		"Yeah, I've seen them. Came in here not two days ago, wanting some horses and supplies. Not the sort of people I'd want to meet at night, if you catch my meaning.",
		'investigation_complete',
		[
			(call_script,'script_object_set_flag',obj_quest,'qst_ronin_investigate_bandit_activity',slot_quest_flags,riqf_innkeeper,true),
			# (quest_get_slot,':quest_flags','qst_ronin_investigate_bandit_activity',slot_quest_flags),
			# (call_script,'script_set_flag_bit',':quest_flags',3,1),
			# (quest_set_slot,'qst_ronin_investigate_bandit_activity',slot_quest_flags,reg0),
			]],
	[anyone,'investigation_merchant_1',[],"Sorry, I haven't heard of any bandits around.",'investigation_failed',[]],
	[anyone|plyr,'investigation_complete',[],"Thank you, you've been very helpful.",'investigation_end',[]],
    [anyone|plyr,'investigation_failed',[],"Well, thanks for your time.",'investigation_end',[]],
	[anyone,'investigation_end',[],'No problem. Good day.','close_window',[]],
    [anyone|plyr,"merchant_talk_2",[],"Nothing, thanks.","close_window",[]],
    [anyone,"merchant_gossip_1",[(eq,'$g_conversation_troop',"trp_city_5_merchant"),
                                 (check_quest_active,'qst_class_merchant'),
								 (neq,"$merchant_intro_quest_given",1)],
     "Actually, I have a job for you...","intro_merchant_quest",[]],
    [anyone|plyr,"intro_merchant_quest",[],"Go on...","intro_merchant_quest_2",[]],
    [anyone,"intro_merchant_quest_2",[],"My associate in Kakogawa is having a difficult time bringing his goods to a wider market. If you help him out, you could be well rewarded later.",
     "intro_merchant_quest_3",[]],
    [anyone|plyr,"intro_merchant_quest_3",[],"This could be interesting. I'll do it.","intro_merchant_quest_accepted",[]],
    [anyone|plyr,"intro_merchant_quest_3",[],"I don't work for free. Sorry.","intro_merchant_quest_denied",[]],
    [anyone,"intro_merchant_quest_accepted",[],"Very good. I'm giving you a letter of introduction so he'll know I sent you. Do well, and the world of the merchant guilds may open its doors to you.",
     "close_window",
     [
         (assign,"$merchant_intro_quest_given",1),
         (assign,"$merchant_intro_quest_complete",0),
		 (quest_set_slot,'qst_merchant_intro_letter',slot_quest_target_troop,'trp_city_8_merchant'),
		 (str_store_party_name,s11,hyogo),
         (str_store_party_name,s10,kakogawa),
		 (str_store_troop_name,s12,'$g_conversation_troop'),
		 (setup_quest_text,'qst_merchant_intro_letter'),
		 (setup_quest_giver,'qst_merchant_intro_letter',s12),
         (call_script,'script_start_quest',"qst_merchant_intro_letter")
         ]],
    [anyone,"intro_merchant_quest_denied",[],"Well, suit yourself.","close_window",[]],
    [anyone,"merchant_gossip_1",
		[
			(eq,'$g_conversation_troop',"trp_city_12_merchant"),
			(eq,'$g_merchant_join_za_flag',true),
			(neg|check_quest_active,'qst_merchant_salt_za_1'),
			],
     "Well, actually...","salt_za_1",[]],
    [anyone,"merchant_gossip_1",[],"Nothing. Nothing at all.","merchant_pre_talk",[]],
    [anyone,"merchant_goods",[],"Of course. Have a look...","merchant_pre_talk",[(change_screen_trade,0)]],
    [anyone,"merchant_pre_talk",[],"Anything else?","merchant_talk_2",[]],
    [anyone,"begin_merchant_quest_1",[],"Ah, finally! I got this shipment of imported goods, but nowhere to sell them. If you can sell these goods to the merchants in  Hyogo and Himeji, I can get a regular route established. I would reward you handsomely for this.",
     "begin_merchant_quest_1a",[]],
    [anyone|plyr,"begin_merchant_quest_1a",[],"I'll do it.","begin_merchant_quest_1b",[]],
    [anyone,"begin_merchant_quest_1b",[(store_free_inventory_capacity,reg2,"trp_player"),
                                       (lt,reg2,8)],
     "It would appear you don't have enough room for all the product. How about clearing some space...",
     "begin_merchant_quest_1b",[(change_screen_trade,0)]],
    [anyone,"begin_merchant_quest_1b",[],"Thank you. Remember, once you've sold the goods, return here with the money. Hopefully, we'll make a considerable sum on this venture. Good luck.",
     "close_window",
     [
         (call_script,'script_end_quest',"qst_merchant_intro_letter"),
         (troop_add_items,"trp_player","itm_imported_tea",8),
		 (quest_set_slot,'qst_merchant_sell_tea',slot_quest_item_1,'itm_imported_tea'),
         (quest_set_slot,'qst_merchant_sell_tea',slot_quest_item_1_cnt,8),
         (quest_set_slot,'qst_merchant_sell_tea',slot_quest_item_1_value,0),
         (call_script,'script_start_quest',"qst_merchant_sell_tea"),
         ]],
    [anyone,"merchant_quest_1_progress",[],"Yes?","merchant_quest_1_progress_b",[]],
    [anyone|plyr,"merchant_quest_1_progress_b",
		[
			(quest_slot_ge,'qst_merchant_sell_tea',slot_quest_item_1_value,1),
			(quest_get_slot,reg10,'qst_merchant_sell_tea',slot_quest_item_1_value),
			],
	"I was able to sell the tea for {reg10} mon.","merchant_quest_1_progress_c",[]],
    [anyone|plyr,"merchant_quest_1_progress_b",
		[
			(quest_slot_lt,'qst_merchant_sell_tea',slot_quest_item_1_value,1),
			],
	"I haven't sold the tea yet.","merchant_quest_1_progress_d",[]],
    [anyone,"merchant_quest_1_progress_c",
		[
			(quest_slot_ge,'qst_merchant_sell_tea',slot_quest_item_1_value,1201),
			],
		"Great work! This is going be a fine new venture. Thanks for all your help. By the way, here's your reward.","close_window",
     [
         (troop_add_gold,"trp_player",500),
         (add_xp_as_reward,1000),
         (call_script,'script_modify_fame',20),
         (call_script,'script_end_quest',"qst_merchant_sell_tea"),
		 (assign,'$g_merchant_join_za_flag',true),
         ]],
    [anyone,"merchant_quest_1_progress_c",
		[
			(quest_slot_lt,'qst_merchant_sell_tea',slot_quest_item_1_value,1201),
			],
	"Well, I was hoping to make more, but your still turned a profit. Thanks for all your help. By the way, here's your reward.","close_window",
     [
         (troop_add_gold,"trp_player",250),
         (add_xp_as_reward,500),
         (call_script,'script_modify_fame',20),
         (call_script,'script_end_quest',"qst_merchant_sell_tea")
         ]],
    [anyone,"merchant_quest_1_progress_d",[],"Well, get to it. Time is money.","close_window",[]],
    [anyone,"merchant_quest_sell_goods",[],"Tea, eh? Let me have a look at it.","merchant_quest_sell_goods_2",
		[
			(store_random_in_range,"$chance_to_sell",0,15),
			]],
    [anyone|plyr,"merchant_quest_sell_goods_2",[],"By all means. It is a fine product.","merchant_quest_sell_goods_3",[]],
    [anyone,"merchant_quest_sell_goods_3",
		[
			(store_item_kind_count,reg2,"itm_imported_tea","trp_player"),
			(lt,reg2,4),
			],
     "I would have bought four crates, but your don't seem to have that many.","close_window",[]],
    [anyone,"merchant_quest_sell_goods_3",
		[
			(store_attribute_level,':chr_level',"trp_player",ca_charisma),
			(store_skill_level,':persuasion_skill',skl_persuasion,'trp_player'),
			(store_skill_level,':trade_skill',skl_trade,'trp_player'),
			(val_add,':chr_level',':persuasion_skill'),
			(val_add,':chr_level',':trade_skill'),
			(le,"$chance_to_sell",':chr_level'),
			],
     "Indeed it is! I'll take four crates.","merchant_quest_sell_goods_4",
     [
         (troop_remove_items,"trp_player","itm_imported_tea",4),
         (val_mul,reg0,2),
		 (quest_get_slot,':tea_sales','qst_merchant_sell_tea',slot_quest_item_1_value),
         (val_add,":tea_sales",reg0),
         (quest_set_slot,'qst_merchant_sell_tea',slot_quest_item_1_value,':tea_sales'),
         ]],
    [anyone,"merchant_quest_sell_goods_3",
		[
			(store_attribute_level,':chr_level',"trp_player",ca_charisma),
			(store_skill_level,':persuasion_skill',skl_persuasion,'trp_player'),
			(store_skill_level,':trade_skill',skl_trade,'trp_player'),
			(val_add,':chr_level',':persuasion_skill'),
			(val_add,':chr_level',':trade_skill'),
			(ge,"$chance_to_sell",':chr_level'),
			],
     "It's not bad. I'll take four crates.","merchant_quest_sell_goods_4",
     [
         (troop_remove_items,"trp_player","itm_imported_tea",4),
         (val_mul,reg0,3),
         (val_div,reg0,2),
         (quest_get_slot,':tea_sales','qst_merchant_sell_tea',slot_quest_item_1_value),
         (val_add,":tea_sales",reg0),
         (quest_set_slot,'qst_merchant_sell_tea',slot_quest_item_1_value,':tea_sales'),
         ]],
    [anyone|plyr,"merchant_quest_sell_goods_4",[],"Thank you. It's been a pleasure doing business with you.","close_window",[]],
    [anyone|plyr,"salt_za_1",[],"Yes...go on.","salt_za_2",[]],
    [anyone,"salt_za_2",[],"It is rumored that you've got a good head on your shoulders. I represent the salt za here in Nara. We're looking for some good people, such as yourself.","salt_za_3",[]],
    [anyone|plyr,"salt_za_3",[],"I'm listening.","salt_za_4",[]],
    [anyone,"salt_za_4",[],"Good. To prove yourself, you'll need to run a shipment of salt from Sakai to Utano. I'll warn you now: we have a good lock on the salt business around here, and the other za are always trying to butt in. Be wary of raiders.","salt_za_5",[]],
    [anyone|plyr,"salt_za_5",[],"Sounds good. I'm in.","salt_za_6",[]],
    [anyone|plyr,"salt_za_5",[],"You know, I'd rather not.","salt_za_end",[]],
    [anyone,"salt_za_6",
		[
			],
    "Great. Meet with the merchant in Sakai. He'll give you more information there.","close_window",
		[
			(quest_set_slot,'qst_merchant_salt_za_1',slot_quest_giver,"$g_conversation_troop"),
			(quest_set_slot,'qst_merchant_salt_za_1',slot_quest_target_troop,'trp_city_10_merchant'),
			(call_script,'script_start_quest',"qst_merchant_salt_za_1"),
			]],
    [anyone,"salt_za_end",[],"Well, maybe another time.","close_window",[]],

#Begin weaponsmith dialogs
    [anyone,"start",
		[
			(store_conversation_troop,'$g_conversation_troop'),
			(is_between,'$g_conversation_troop',weaponsmiths_begin,weaponsmiths_end),
			],
     "Greetings, {Tono/Hime}...","weaponsmith_talk_1",[]],
    [anyone,"weaponsmith_talk_1",[],"What can I do for you?","weaponsmith_talk_2",[]],
    [anyone|plyr,"weaponsmith_talk_2",[],"I'd like to see your wares.","weaponsmith_goods",[]],
	[anyone|plyr,'weaponsmith_talk_2',[(eq,1,0)],'Could you evaluate my weapons?','weaponsmith_eval',[]],
	[anyone|plyr,'weaponsmith_talk_2',[(eq,1,0)],'I was wondering if you could do some repair work.','weaponsmith_repair',[]],
	[anyone|plyr,'weaponsmith_talk_2',
		[
			(check_quest_concluded,'qst_repair_weapon'),
			],
		'You have repaired my item?',
		'weaponsmith_item_repaired',
		[]],
	[anyone|plyr,'weaponsmith_talk_2',
		[
			(check_quest_active,'qst_ronin_investigate_bandit_activity'),
			(quest_slot_eq,'qst_ronin_investigate_bandit_activity',slot_quest_party_1,'$g_encountered_party'),
			],
		"I'm looking to some bandits seen near here. Have you heard anything?",'investigation_weaponsmith_1',[]],
	[anyone,'investigation_weaponsmith_1',
		[
			(call_script,'script_cf_object_flag_set',obj_quest,'qst_ronin_investigate_bandit_activity',slot_quest_flags,riqf_weaponsmith),
			(quest_get_slot,reg20,'qst_ronin_investigate_bandit_activity',slot_quest_flags),
			(display_message,'@Flag value: {reg20}',purple_text),
			# (call_script,'script_get_flag_bit',reg20,3),
			# (eq,reg0,1),
			],
		"Come to think of it, yeah. They came in here a few days ago, throwing a lot of mon around. The head one picked up a few nice things, I'll admit, and I wasn't going to ask too many questions. I've got a family to worry about and all.",
		'investigation_complete',
		[
			(call_script,'script_object_set_flag',obj_quest,'qst_ronin_investigate_bandit_activity',slot_quest_flags,riqf_kokujin,true),
			# (call_script,'script_set_flag_bit',reg20,4,1),
			# (quest_set_slot,'qst_ronin_investigate_bandit_activity',slot_quest_flags,reg0),
			]],
	[anyone,'investigation_weaponsmith_1',
		[
			(store_attribute_level,':chr_level','trp_player',ca_charisma),
			(val_div,':chr_level',2),
			(store_random_in_range,':roll',0,10),
			# (display_message,'@{reg1} / 10',purple_text),
			(le,':roll',':chr_level'),
			],
		"Come to think of it, yeah. They came in here a few days ago, throwing a lot of mon around. The head one picked up a few nice things, I'll admit, and I wasn't going to ask too many questions. I've got a family to worry about and all.",
		'investigation_complete',
		[
			(call_script,'script_object_set_flag',obj_quest,'qst_ronin_investigate_bandit_activity',slot_quest_flags,riqf_kokujin,true),
			# (quest_get_slot,':quest_flags','qst_ronin_investigate_bandit_activity',slot_quest_flags),
			# (call_script,'script_set_flag_bit',':quest_flags',4,1),
			# (quest_set_slot,'qst_ronin_investigate_bandit_activity',slot_quest_flags,reg0),
			]],
	[anyone,'investigation_weaponsmith_1',[],"Sorry, I haven't heard of any bandits around.",'investigation_failed',[]],
    [anyone|plyr,"weaponsmith_talk_2",[(store_conversation_troop,reg2),
                                       (eq,reg2,"trp_town_5_weaponsmith"),
                                       (check_quest_active,'qst_bladesmith_2'),
                                       (troop_slot_eq,reg2,50,1)],
     "I have come back for the sword.","weaponsmith_talk_6",[]],
    [anyone|plyr,"weaponsmith_talk_2",[(store_conversation_troop,reg2),
                                       (eq,reg2,"trp_town_5_weaponsmith"),
                                       (check_quest_active,'qst_bladesmith'),
                                       (this_or_next|player_has_item,"itm_iron_bar"),
                                       (player_has_item,"itm_iron_bars"),
                                       (player_has_item,"itm_tamahagane_nugget"),
                                       (player_has_item,"itm_copper_bar"),
                                       (player_has_item,"itm_silk")],
     "I have brought the items you require.","weaponsmith_talk_5",[]],
    [anyone|plyr,"weaponsmith_talk_2",[(store_conversation_troop,reg2),
                                       (eq,reg2,"trp_town_5_weaponsmith"),
                                       (troop_slot_eq,"trp_yamamatsu",slot_troop_intro,1),
                                       (neg|troop_slot_eq,reg2,slot_troop_intro,1)],
     "I understand you do custom work.","weaponsmith_talk_3",[]],
    [anyone|plyr,"weaponsmith_talk_2",[],"Nothing, thanks.","close_window",[]],
    [anyone,"weaponsmith_goods",[],"Of course.","weaponsmith_pre_talk",[[change_screen_trade]]],
    [anyone,"weaponsmith_pre_talk",[],"Anthing else?","weaponsmith_talk_2",[]],
    [anyone,"weaponsmith_talk_3",[],"Yes, but what you ask requires many things. I will need a nugget of tamahagane, a bar of iron, a bar of copper, and one bolt of silk. Bring these to me, and I'll create a blade like none other.","weaponsmith_talk_4",
     [(troop_set_slot,'$g_conversation_troop',slot_troop_intro,1)]],
    [anyone|plyr,"weaponsmith_talk_4",[],"Very well. I will return with what you require.","close_window",
		[
			(quest_set_slot,"qst_bladesmith",slot_quest_giver,'$g_conversation_troop'),
			(call_script,'script_start_quest',"qst_bladesmith"),
			]],
    [anyone,"weaponsmith_talk_5",[(call_script,'script_end_quest',"qst_bladesmith"),
                                  (troop_remove_item,"trp_player","itm_copper_bar"),
                                  (troop_remove_item,"trp_player","itm_tamahagane_nugget"),
                                  (troop_remove_item,"trp_player","itm_silk"),
                                  (try_begin),
                                      (player_has_item,"itm_iron_bar"),
                                      (troop_remove_item,"trp_player","itm_iron_bar"),
                                  (else_try),
                                      (player_has_item,"itm_iron_bars"),
                                      (troop_remove_item,"trp_player","itm_iron_bars"),
                                  (try_end)],
     "Good. Return in five days, and you will have your sword.","close_window",
     [(store_current_day,"$bladesmith_start_day"),
      (store_add,"$bladesmith_end_day",'$bladesmith_start_day',5),
      (assign,reg1,"$bladesmith_end_day"),
      (setup_quest_text,"qst_bladesmith_2"),
      (call_script,'script_start_quest',"qst_bladesmith_2")]],
    [anyone,"weaponsmith_talk_6",[],"It is my greatest creation. I shall not make its equal again.","sharp_wave1",
		[
			(call_script,'script_end_quest',"qst_bladesmith_2"),
			(troop_set_slot,'trp_town_5_weaponsmith',50,0),
			(troop_add_item,"trp_player","itm_sharp_wave")
			]],
	[anyone|plyr,'sharp_wave1',[],"You've got that right...where did you learn to make swords anyway?",'sharp_wave2',[]],
	[anyone,'sharp_wave2',[],'In a land far, far away','sharp_wave3',[]],
	[anyone|plyr,'sharp_wave3',[],"Really? Because it looks like something out of an oni's mouth.",'sharp_wave4',[]],
	[anyone,'sharp_wave4',[],'Nonetheless, I shall not make its equal again.','close_window',[]],
	[anyone,'weaponsmith_repair',[],'Sure. What would you like me to repair?','weaponsmith_repair_choose',[]],
	[anyone|plyr,'weaponsmith_repair_choose',
		[
			(call_script,'script_cf_select_repair_weapon','trp_player',ek_item_0),
			],
		'{s3}','weaponsmith_repair_weapon',[(assign,'$g_slot_to_repair',0)]],
	[anyone|plyr,'weaponsmith_repair_choose',
		[
			(call_script,'script_cf_select_repair_weapon','trp_player',ek_item_1),
			],
		'{s3}','weaponsmith_repair_weapon',[(assign,'$g_slot_to_repair',1)]],
	[anyone|plyr,'weaponsmith_repair_choose',
		[
			(call_script,'script_cf_select_repair_weapon','trp_player',ek_item_2),
			],
		'{s3}','weaponsmith_repair_weapon',[(assign,'$g_slot_to_repair',2)]],
	[anyone|plyr,'weaponsmith_repair_choose',
		[
			(call_script,'script_cf_select_repair_weapon','trp_player',ek_item_3),
			],
		'{s3}','weaponsmith_repair_weapon',[(assign,'$g_slot_to_repair',3)]],
	[anyone|plyr,'weaponsmith_repair_choose',[],'Never mind.','weaponsmith_talk_1',[]],
	[anyone,'weaponsmith_repair_weapon',
		[
			(troop_get_inventory_slot,reg10,'trp_player','$g_slot_to_repair'),
			(troop_get_inventory_slot_modifier,reg11,'trp_player','$g_slot_to_repair'),
			(is_between,reg10,repairable_items_begin,repairable_items_end),
			],
		'Very well. Return tomorrow, and it should be finished','close_window',
		[
			(str_store_party_name,1,'$g_encountered_party'),
			(str_store_item_name,2,reg10),
			(quest_set_slot,'qst_repair_weapon',slot_quest_item_1,reg10),
			(quest_set_slot,'qst_repair_weapon',slot_quest_item_1_imod,reg11),
			(store_conversation_troop,':weaponsmith'),
			(quest_set_slot,'qst_repair_weapon',slot_quest_giver,':weaponsmith'),
			(troop_remove_items,'trp_player',reg10,1),
			(val_mul,reg0,2),
			(val_div,reg0,3),
			(quest_set_slot,'qst_repair_weapon',slot_quest_item_1_value,reg0),
			(setup_quest_text,'qst_repair_weapon'),
			(start_quest,'qst_repair_weapon'),
			]],
	[anyone,'weaponsmith_repair_weapon',[],"I'm sorry, but I can't fix that",'weaponsmith_talk_1',[]],
	[anyone,'weaponsmith_item_repaired',
		[
			(quest_get_slot,reg1,'qst_repair_weapon',slot_quest_item_1_value),
			],
		"Yes, of course. The repair will cost {reg1} mon.",'weaponsmith_pay_repair',[]],
	[anyone|plyr,'weaponsmith_pay_repair',
		[	
			(store_troop_gold,':available_cash','trp_player'),
			(quest_get_slot,reg1,'qst_repair_weapon',slot_quest_item_1_value),
			(ge,':available_cash',reg1),
			],
		'Here you are. Thank you for your help.','weaponsmith_talk_1',
		[
			(troop_remove_gold,'trp_player',reg1),
			(quest_get_slot,':item','qst_repair_weapon',slot_quest_item_1),
			(quest_get_slot,':item_imod','qst_repair_weapon',slot_quest_item_1_imod),
			(troop_add_item,'trp_player',':item',':item_imod'),
			(call_script,'script_end_quest','qst_repair_weapon'),
			]],
	[anyone|plyr,'weaponsmith_pay_repair',[],"I'm afraid I don't have that much on me.",'weaponsmith_cant_pay',[]],
	[anyone,'weaponsmith_cant_pay',[],'Well, come back when you can pay.','close_window',[]],
	[anyone,'weaponsmith_eval',[],'Of course.^{s1}','weaponsmith_talk_1',
		[
			(troop_get_inventory_slot,':item_1','trp_player',ek_item_0),
			(troop_get_inventory_slot,':item_2','trp_player',ek_item_1),
			(troop_get_inventory_slot,':item_3','trp_player',ek_item_2),
			(troop_get_inventory_slot,':item_4','trp_player',ek_item_3),
			(str_clear,s1),
			(try_begin),
				(gt,':item_1',0),
				(troop_get_inventory_slot_modifier,reg1,'trp_player',ek_item_0),
				(item_get_slot,reg2,':item_1',slot_item_durability),
				(str_store_item_name,2,':item_1'),
				(str_store_string,s1,'@{s1}{s2}, mod:{reg1}, dur:{reg2}^'),
			(try_end),
			(try_begin),
				(gt,':item_2',0),
				(troop_get_inventory_slot_modifier,reg1,'trp_player',ek_item_1),
				(item_get_slot,reg2,':item_2',slot_item_durability),
				(str_store_item_name,2,':item_2'),
				(str_store_string,s1,'@{s1}{s2}, mod:{reg1}, dur:{reg2}^'),
			(try_end),
			(try_begin),
				(gt,':item_3',0),
				(troop_get_inventory_slot_modifier,reg1,'trp_player',ek_item_2),
				(item_get_slot,reg2,':item_3',slot_item_durability),
				(str_store_item_name,2,':item_3'),
				(str_store_string,s1,'@{s1}{s2}, mod:{reg1}, dur:{reg2}^'),
			(try_end),
			(try_begin),
				(gt,':item_4',0),
				(troop_get_inventory_slot_modifier,reg1,'trp_player',ek_item_3),
				(item_get_slot,reg2,':item_4',slot_item_durability),
				(str_store_item_name,2,':item_4'),
				(str_store_string,s1,'@{s1}{s2}, mod:{reg1}, dur:{reg2}^'),
			(try_end),
			]
		],
#Begin armorer dialogs
    [anyone,"start",[(store_conversation_troop,reg1),(is_between,reg1,armorers_begin,armorers_end)],
     "Greetings, {Tono/Hime}...","armorer_talk_1",[]],
    [anyone,"armorer_talk_1",[],"What can I do for you?","armorer_talk_2",[]],
    [anyone|plyr,"armorer_talk_2",[],"I'd like to see your wares.","armorer_goods",[]],
	[anyone|plyr,'armorer_talk_2',[],'Could you have a look at my gear?','armorer_eval',[]],
    [anyone|plyr,"armorer_talk_2",[],"Nothing, thanks.","close_window",[]],
    [anyone,"armorer_goods",[],"Of course.","armorer_pre_talk",[(change_screen_trade,0)]],
	[anyone,'armorer_eval',[],'Of course.^{s1}','armorer_pre_talk',
		[
			(troop_get_inventory_slot,':head_armor','trp_player',ek_head),
			(troop_get_inventory_slot,':body_armor','trp_player',ek_body),
			(troop_get_inventory_slot,':foot_armor','trp_player',ek_foot),
			(troop_get_inventory_slot,':hand_armor','trp_player',ek_gloves),
			(str_clear,s1),
			(try_begin),
				(gt,':head_armor',0),
				(troop_get_inventory_slot_modifier,reg1,'trp_player',ek_head),
				(item_get_slot,reg2,':head_armor',slot_item_durability),
				(str_store_item_name,2,':head_armor'),
				(str_store_string,s1,'@{s1}{s2}, mod:{reg1}, dur:{reg2}^'),
			(try_end),
			(try_begin),
				(gt,':body_armor',0),
				(troop_get_inventory_slot_modifier,reg1,'trp_player',ek_body),
				(item_get_slot,reg2,':body_armor',slot_item_durability),
				(str_store_item_name,2,':body_armor'),
				(str_store_string,s1,'@{s1}{s2}, mod:{reg1}, dur:{reg2}^'),
			(try_end),
			(try_begin),
				(gt,':foot_armor',0),
				(troop_get_inventory_slot_modifier,reg1,'trp_player',ek_foot),
				(item_get_slot,reg2,':foot_armor',slot_item_durability),
				(str_store_item_name,2,':foot_armor'),
				(str_store_string,s1,'@{s1}{s2}, mod:{reg1}, dur:{reg2}^'),
			(try_end),
			(try_begin),
				(gt,':hand_armor',0),
				(troop_get_inventory_slot_modifier,reg1,'trp_player',ek_gloves),
				(item_get_slot,reg2,':hand_armor',slot_item_durability),
				(str_store_item_name,2,':hand_armor'),
				(str_store_string,s1,'@{s1}{s2}, mod:{reg1}, dur:{reg2}^'),
			(try_end),
			]],
    [anyone,"armorer_pre_talk",[],"Anthing else?","armorer_talk_2",[]],
# sensei apprentices
	[anyone,'start',
		[
			(store_conversation_troop,reg1),
			(is_between,reg1,'trp_south_kyoto_dojo_apprentice','trp_kingmaker'),
			(check_quest_active,'qst_recruit_apprentice'),
			(quest_slot_eq,'qst_recruit_apprentice',slot_quest_troop_1,reg1),
			(hero_can_join,reg1),
			],
		'I am ready to begin my travels with you. Let us be off.','close_window',[]],
	[anyone,'start',
		[
			(store_conversation_troop,reg1),
			(is_between,reg1,'trp_south_kyoto_dojo_apprentice','trp_kingmaker'),
			(check_quest_active,'qst_recruit_apprentice'),
			(quest_slot_eq,'qst_recruit_apprentice',slot_quest_troop_1,reg1),
			(neg|hero_can_join,reg1),
			],
		'I am ready to begin my travels with you, but you seem to have no room.','close_window',[]],
	[anyone,'start',
		[
			(store_conversation_troop,reg1),
			(is_between,reg1,'trp_south_kyoto_dojo_apprentice','trp_kingmaker'),
			(store_current_scene,':dojo'),
			(scene_slot_eq,':dojo',slot_dojo_sensei_away,0),
			],
		'My master awaits you. Please speak with him.','close_window',[]],
	[anyone,'start',
		[
			(store_conversation_troop,reg1),
			(is_between,reg1,'trp_south_kyoto_dojo_apprentice','trp_kingmaker'),
			(store_current_scene,':dojo'),
			(scene_slot_eq,':dojo',slot_dojo_sensei_away,1),
			],
		'My master is away training. Please come back another day.','close_window',[]],
	
#Begin dojo masters
    [anyone,"start",[(store_conversation_troop,reg1),
                     (eq,reg1,'$g_town_sensei'),
                     (check_quest_active,'qst_companion_training'),
					 (check_quest_succeeded,'qst_companion_training'),
					 (quest_get_slot,'$g_training_companion','qst_companion_training',slot_quest_companion_training_companion),
					 ],
     "You friend is an excellent student. My instruction was well received.","dojo_end_1",
		[]],
    [anyone|plyr,"dojo_end_1",[],"Thank you, Sensei.","dojo_end_2",[]],
    [anyone,"dojo_end_2",[(neg|hero_can_join,0)],"I would release your friend back into your care, but it seems there is no room.","close_window",[]],
    [anyone,"dojo_end_2",[],"I release your friend back into your care. Fare well.","close_window",
		[
			(troop_join,'$g_training_companion'),
			(call_script,"script_companion_training",'$g_training_companion',2),
			(call_script,'script_end_quest',"qst_companion_training"),
			]],
    [anyone,"start",[(store_conversation_troop,reg1),
                     (eq,reg1,'$g_town_sensei'),
                     (troop_slot_neq,reg1,slot_sensei_begin_kengo,1),
                     (eq,"$waiting_for_training_fight_result",0),
                     (eq,"$training_fight_won",1)],
     "You have perfomed well. I look forward to seeing you again.","close_window",
     [(add_xp_as_reward,50),
      (assign,"$waiting_for_training_fight_result",-1)]],
    [anyone,"start",[(store_conversation_troop,reg1),
                     (eq,reg1,'$g_town_sensei'),
                     (troop_slot_neq,reg1,slot_sensei_begin_kengo,1),
                     (eq,"$waiting_for_training_fight_result",0),
                     (eq,"$training_fight_won",0)],
     "Even in defeat, lessons can be learned. I look forward to seeing you again.","close_window",
     [(assign,"$waiting_for_training_fight_result",-1)]],
    [anyone,"start",[(store_conversation_troop,reg1),
                     (eq,reg1,'$g_town_sensei'),
                     (troop_slot_eq,'$g_town_sensei',slot_sensei_begin_kengo,1),
                     (troop_slot_eq,'$g_town_sensei',slot_sensei_difficulty,5),
                     (eq,"$waiting_for_training_fight_result",0),
                     (eq,"$training_fight_won",1),
					 (try_begin),
                            (eq,"$g_town_sensei","trp_mitsumaru"),
                            (str_store_string,s10,"@Crouching Tiger"),
                     (else_try),
                            (eq,"$g_town_sensei","trp_tomomoto"),
                            (str_store_string,s10,"@Hidden Dragon"),
                     (else_try),
                            (eq,"$g_town_sensei","trp_teruhisa"),
                            (str_store_string,s10,"@Praying Mantis"),
                     (else_try),
                            (eq,"$g_town_sensei","trp_kiyouji"),
                            (str_store_string,s10,"@Shining Moon"),
                     (else_try),
                            (eq,"$g_town_sensei","trp_ietsuru"),
                            (str_store_string,s10,"@Iron Snake"),
                     (else_try),
                            (eq,"$g_town_sensei","trp_tsunetomo"),
                            (str_store_string,s10,"@Flying Crane"),
                     (else_try),
                            (eq,"$g_town_sensei","trp_ujiaru"),
                            (str_store_string,s10,"@Eagle Claw"),
                     (else_try),
                            (eq,"$g_town_sensei","trp_michimori"),
                            (str_store_string,s10,"@Swooping Hawk"),
                     (try_end)],
     "You have surpassed my best students, {playername}. There is nothing more I can teach you. You are a Master of the {s10} school.","kengo_end",
     [(add_xp_as_reward,1000),
	  (troop_get_slot,':training_flag','$g_town_sensei',slot_sensei_flag),
	  (troop_get_slot,':training_flags','trp_player',slot_player_training_flags),
	  (assign,reg10,':training_flags'),
	  (display_message,'@Training flags: {reg10}',debug_text),
	  (call_script,'script_set_flag_bit',':training_flags',':training_flag',1),
	  (display_message,'@Training flags after set_flag_bit: {reg0}',debug_text),
	  (troop_set_slot,'trp_player',slot_player_training_flags,reg0),
	  (quest_set_slot,'qst_kengo_training',slot_quest_giver,0),
	  (call_script,'script_end_quest','qst_kengo_training'),
	  (try_begin),
         (store_skill_level,reg1,skl_power_strike,"trp_player"),
         (lt,reg1,10),
         (troop_get_slot,reg2,"$g_sensei_trainer",slot_sensei_skl_ps),
         (troop_raise_skill,"trp_player",skl_power_strike,reg2),
     (else_try),
         (store_skill_level,reg1,skl_power_draw,"trp_player"),
         (lt,reg1,10),
         (troop_get_slot,reg2,"$g_sensei_trainer",slot_sensei_skl_pd),
         (troop_raise_skill,"trp_player",skl_power_draw,reg2),
     (else_try),
         (store_skill_level,reg1,skl_power_throw,"trp_player"),
         (lt,reg1,10),
         (troop_get_slot,reg2,"$g_sensei_trainer",slot_sensei_skl_pt),
         (troop_raise_skill,"trp_player",skl_power_throw,reg2),
     (else_try),
         (store_skill_level,reg1,skl_weapon_master,"trp_player"),
         (lt,reg1,10),
         (troop_get_slot,reg2,"$g_sensei_trainer",slot_sensei_skl_wm),
         (troop_raise_skill,"trp_player",skl_weapon_master,reg2),
     (else_try),
         (store_skill_level,reg1,skl_athletics,"trp_player"),
         (lt,reg1,10),
         (troop_get_slot,reg2,"$g_sensei_trainer",slot_sensei_skl_ath),
         (troop_raise_skill,"trp_player",skl_athletics,reg2),
     (try_end),
     (troop_get_slot,reg(12),"$g_town_sensei",slot_sensei_prof_oh),
     (troop_raise_proficiency_linear,"trp_player",one_handed,reg(12)),
     (troop_get_slot,reg(13),"$g_town_sensei",slot_sensei_prof_th),
     (troop_raise_proficiency_linear,"trp_player",two_handed,reg(13)),
     (troop_get_slot,reg(14),"$g_town_sensei",slot_sensei_prof_pl),
     (troop_raise_proficiency_linear,"trp_player",polearms,reg(14)),
     (troop_get_slot,reg(15),"$g_town_sensei",slot_sensei_prof_ar),
     (troop_raise_proficiency_linear,"trp_player",archery,reg(15)),
     (troop_get_slot,reg(16),"$g_town_sensei",slot_sensei_prof_tr),
     (troop_raise_proficiency_linear,"trp_player",throwing,reg(16)),
     (troop_set_slot,'$g_town_sensei',slot_sensei_begin_kengo,0),
      (assign,"$waiting_for_training_fight_result",-1),
      (assign,"$training_fight_won",0),
	  ]],
	[anyone|plyr,'kengo_end',[],'Thank you, Sensei','kengo_end_1',[]],
	[anyone,'kengo_end_1',[],'My apprentice has also completed my training, and shall follow you hence forth','kengo_end_2',[]],
	[anyone|other(trp_south_kyoto_dojo_apprentice),'kengo_end_2',
		[
			(troop_slot_eq,'$g_town_sensei',slot_sensei_apprentice,'trp_south_kyoto_dojo_apprentice'),
			(hero_can_join,0),
			],
		"I am honored to join you, {Tono/Hime}.",'kengo_end_final',
		[
			(troop_join,'trp_south_kyoto_dojo_apprentice'),
			(troop_set_slot,'trp_south_kyoto_dojo_apprentice',slot_troop_has_joined,1),
			]],
	[anyone|other(trp_south_kyoto_dojo_apprentice),'kengo_end_2',
		[
			(troop_slot_eq,'$g_town_sensei',slot_sensei_apprentice,'trp_south_kyoto_dojo_apprentice'),
			(neg|hero_can_join,0),
			(start_quest,'qst_recruit_apprentice'),
			(quest_set_slot,'qst_recruit_apprentice',slot_quest_troop_1,'trp_south_kyoto_dojo_apprentice'),
			],
		"I am honored to join you, {Tono/Hime}, but you have no room.",'kengo_end_final',[]],
	[anyone|other(trp_yodo_dojo_apprentice),'kengo_end_2',
		[
			(troop_slot_eq,'$g_town_sensei',slot_sensei_apprentice,'trp_yodo_dojo_apprentice'),
			(hero_can_join,0),
			],
		"I am honored to join you, {Tono/Hime}.",'kengo_end_final',
		[
			(troop_join,'trp_yodo_dojo_apprentice'),
			(troop_set_slot,'trp_yodo_dojo_apprentice',slot_troop_has_joined,1),
			]],
	[anyone|other(trp_yodo_dojo_apprentice),'kengo_end_2',
		[
			(troop_slot_eq,'$g_town_sensei',slot_sensei_apprentice,'trp_yodo_dojo_apprentice'),
			(neg|hero_can_join,0),
			(start_quest,'qst_recruit_apprentice'),
			(quest_set_slot,'qst_recruit_apprentice',slot_quest_troop_1,'trp_yodo_dojo_apprentice'),
			],
		"I am honored to join you, {Tono/Hime}, but you have no room.",'kengo_end_final',[]],
	[anyone|other(trp_haga_dojo_apprentice),'kengo_end_2',
		[
			(troop_slot_eq,'$g_town_sensei',slot_sensei_apprentice,'trp_haga_dojo_apprentice'),
			(hero_can_join,0),
			],
		"I am honored to join you, {Tono/Hime}.",'kengo_end_final',
		[
			(troop_join,'trp_haga_dojo_apprentice'),
			(troop_set_slot,'trp_haga_dojo_apprentice',slot_troop_has_joined,1),
			]],
	[anyone|other(trp_haga_dojo_apprentice),'kengo_end_2',
		[
			(troop_slot_eq,'$g_town_sensei',slot_sensei_apprentice,'trp_haga_dojo_apprentice'),
			(neg|hero_can_join,0),
			(start_quest,'qst_recruit_apprentice'),
			(quest_set_slot,'qst_recruit_apprentice',slot_quest_troop_1,'trp_haga_dojo_apprentice'),
			],
		"I am honored to join you, {Tono/Hime}, but you have no room.",'kengo_end_final',[]],
	[anyone|other(trp_hikone_dojo_apprentice),'kengo_end_2',
		[
			(troop_slot_eq,'$g_town_sensei',slot_sensei_apprentice,'trp_hikone_dojo_apprentice'),
			(hero_can_join,0),
			],
		"I am honored to join you, {Tono/Hime}.",'kengo_end_final',
		[
			(troop_join,'trp_hikone_dojo_apprentice'),
			(troop_set_slot,'trp_hikone_dojo_apprentice',slot_troop_has_joined,1),
			]],
	[anyone|other(trp_hikone_dojo_apprentice),'kengo_end_2',
		[
			(troop_slot_eq,'$g_town_sensei',slot_sensei_apprentice,'trp_hikone_dojo_apprentice'),
			(neg|hero_can_join,0),
			(start_quest,'qst_recruit_apprentice'),
			(quest_set_slot,'qst_recruit_apprentice',slot_quest_troop_1,'trp_hikone_dojo_apprentice'),
			],
		"I am honored to join you, {Tono/Hime}, but you have no room.",'kengo_end_final',[]],
	[anyone|other(trp_imazu_dojo_apprentice),'kengo_end_2',
		[
			(troop_slot_eq,'$g_town_sensei',slot_sensei_apprentice,'trp_imazu_dojo_apprentice'),
			(hero_can_join,0),
			],
		"I am honored to join you, {Tono/Hime}.",'kengo_end_final',
		[
			(troop_join,'trp_imazu_dojo_apprentice'),
			(troop_set_slot,'trp_imazu_dojo_apprentice',slot_troop_has_joined,1),
			]],
	[anyone|other(trp_imazu_dojo_apprentice),'kengo_end_2',
		[
			(troop_slot_eq,'$g_town_sensei',slot_sensei_apprentice,'trp_imazu_dojo_apprentice'),
			(neg|hero_can_join,0),
			(start_quest,'qst_recruit_apprentice'),
			(quest_set_slot,'qst_recruit_apprentice',slot_quest_troop_1,'trp_imazu_dojo_apprentice'),
			],
		"I am honored to join you, {Tono/Hime}, but you have no room.",'kengo_end_final',[]],
	[anyone|other(trp_iga_dojo_apprentice),'kengo_end_2',
		[
			(troop_slot_eq,'$g_town_sensei',slot_sensei_apprentice,'trp_iga_dojo_apprentice'),
			(hero_can_join,0),
			],
		"I am honored to join you, {Tono/Hime}.",'kengo_end_final',
		[
			(troop_join,'trp_iga_dojo_apprentice'),
			(troop_set_slot,'trp_iga_dojo_apprentice',slot_troop_has_joined,1),
			]],
	[anyone|other(trp_iga_dojo_apprentice),'kengo_end_2',
		[
			(troop_slot_eq,'$g_town_sensei',slot_sensei_apprentice,'trp_iga_dojo_apprentice'),
			(neg|hero_can_join,0),
			(start_quest,'qst_recruit_apprentice'),
			(quest_set_slot,'qst_recruit_apprentice',slot_quest_troop_1,'trp_iga_dojo_apprentice'),
			],
		"I am honored to join you, {Tono/Hime}, but you have no room.",'kengo_end_final',[]],
	[anyone|other(trp_oe_dojo_apprentice),'kengo_end_2',
		[
			(troop_slot_eq,'$g_town_sensei',slot_sensei_apprentice,'trp_oe_dojo_apprentice'),
			(hero_can_join,0),
			],
		"I am honored to join you, {Tono/Hime}.",'kengo_end_final',
		[
			(troop_join,'trp_oe_dojo_apprentice'),
			(troop_set_slot,'trp_oe_dojo_apprentice',slot_troop_has_joined,1),
			]],
	[anyone|other(trp_oe_dojo_apprentice),'kengo_end_2',
		[
			(troop_slot_eq,'$g_town_sensei',slot_sensei_apprentice,'trp_oe_dojo_apprentice'),
			(neg|hero_can_join,0),
			(start_quest,'qst_recruit_apprentice'),
			(quest_set_slot,'qst_recruit_apprentice',slot_quest_troop_1,'trp_oe_dojo_apprentice'),
			],
		"I am honored to join you, {Tono/Hime}, but you have no room.",'kengo_end_final',[]],
	[anyone|other(trp_oya_dojo_apprentice),'kengo_end_2',
		[
			(troop_slot_eq,'$g_town_sensei',slot_sensei_apprentice,'trp_oya_dojo_apprentice'),
			(hero_can_join,0),
			],
		"I am honored to join you, {Tono/Hime}.",'kengo_end_final',
		[
			(troop_join,'trp_oya_dojo_apprentice'),
			(troop_set_slot,'trp_oya_dojo_apprentice',slot_troop_has_joined,1),
			]],
	[anyone|other(trp_oya_dojo_apprentice),'kengo_end_2',
		[
			(troop_slot_eq,'$g_town_sensei',slot_sensei_apprentice,'trp_oya_dojo_apprentice'),
			(neg|hero_can_join,0),
			(start_quest,'qst_recruit_apprentice'),
			(quest_set_slot,'qst_recruit_apprentice',slot_quest_troop_1,'trp_oya_dojo_apprentice'),
			],
		"I am honored to join you, {Tono/Hime}, but you have no room.",'kengo_end_final',[]],
	[anyone,'kengo_end_final',[],'Good day, {playername}.','close_window',[]],
    [anyone,"start",[(store_conversation_troop,reg1),
                     (eq,reg1,"$g_town_sensei"),
                     (troop_slot_eq,'$g_town_sensei',slot_sensei_begin_kengo,1),
                     (eq,"$waiting_for_training_fight_result",0),
                     (eq,"$training_fight_won",0)],
     "Such failure cannot be tolerated. You will start over from the beginning.","close_window",
     [(assign,"$waiting_for_training_fight_result",-1),
      (troop_set_slot,reg1,slot_sensei_difficulty,0),]],
    [anyone,"start",[(store_conversation_troop,reg1),
                     (eq,reg1,"$g_town_sensei"),
                     (troop_slot_eq,'$g_town_sensei',slot_sensei_begin_kengo,1),
                     (eq,"$waiting_for_training_fight_result",0),
                     (eq,"$training_fight_won",1)],
     "Excellent. On to the next match!","close_window",
		[
			(call_script,'script_object_modify_slot',obj_troop,'$g_town_sensei',slot_sensei_difficulty,op_asn,5),
			# (call_script,'script_object_modify_slot',obj_troop,'$g_town_sensei',slot_sensei_difficulty,op_add,1),
			(troop_get_slot,':weapon_type',reg1,slot_sensei_weapon_type),
			(call_script,'script_kengo_training',':weapon_type'),
			(modify_visitors_at_site,'scn_small_field'),
			(reset_visitors),
			(try_begin),
				(eq,':difficulty',1),
				(set_visitor,reg15,reg21),
			(else_try),
				(eq,':difficulty',2),
				(set_visitor,reg15,reg22),
			(else_try),
				(eq,':difficulty',3),
				(set_visitor,reg15,reg20),
				(set_visitor,reg16,reg20),
				(set_visitor,reg17,reg20),
			(else_try),
				(eq,':difficulty',4),
				(set_visitor,reg15,reg20),
				(set_visitor,reg16,reg20),
				(set_visitor,reg17,reg20),
			(else_try),
				(eq,':difficulty',5),
				(set_visitor,reg15,reg20),
				(set_visitor,reg16,reg20),
				(set_visitor,reg17,reg20),
			(try_end),
			(assign,"$training_fight_won",0),
			(assign,"$waiting_for_training_fight_result",-1),
			(set_jump_mission,'mt_kengo_training_fight'),
			(set_jump_entry,reg30),
			(jump_to_scene,'scn_small_field'),
			(change_screen_mission),
			]],
    [anyone,"start",[(store_conversation_troop,reg1),
                     (eq,reg1,"$g_town_sensei"),
                     (quest_slot_eq,'qst_kengo_training',slot_quest_giver,reg1),
					 (troop_slot_eq,'$g_town_sensei',slot_sensei_begin_kengo,1),
                     (troop_slot_eq,'$g_town_sensei',slot_sensei_difficulty,0),
                     (eq,"$waiting_for_training_fight_result",-1)],
     "Your training will consist of bouts with increasing skilled opponents, at first singly, then in groups. If you choose to leave the dojo, I will start you over from the beginning. Are you prepared?","kengo_fight_1",[]],
    [anyone|plyr,"kengo_fight_1",[],"Yes, Sensei.","kengo_fight_2",[]],
    [anyone,"kengo_fight_2",[],"Excellent. Ippon!","close_window",
		[
			(troop_get_slot,':weapon_type','$g_town_sensei',slot_sensei_weapon_type),
			(call_script,'script_kengo_training',':weapon_type'),
			#(display_message,'str_kengo_regs'),
			(modify_visitors_at_site,'scn_small_field'),
			(reset_visitors),
			(set_visitor,reg15,reg20),
			(assign,"$training_fight_won",0),
			(assign,"$waiting_for_training_fight_result",-1),
			(set_jump_mission,'mt_kengo_training_fight'),
			(set_jump_entry,reg30),
			(jump_to_scene,'scn_small_field'),
			(change_screen_mission),			
			]],
    [anyone,"start",[(store_conversation_troop,reg1),
					 (store_current_scene,'$dojo_scene'),
					 #(is_between,reg1,dojo_masters_begin,dojo_masters_end),
					 (eq,reg1,"$g_town_sensei"),
                     (str_store_troop_name,1,reg1)],
     "Welcome to my dojo, young student. I am {s1}.","dojo_1",[]],
    [anyone|plyr,"dojo_1",[],"I seek training, Sensei.","dojo_2",[]],
    [anyone|plyr,"dojo_1",[(this_or_next|main_party_has_troop,trp_haruko),
                           (this_or_next|main_party_has_troop,trp_tsuruhiro),
                           (this_or_next|main_party_has_troop,trp_shinbo),
                           (main_party_has_troop,trp_akikane),
                           (neg|check_quest_active,'qst_companion_training')],
     "One of my companions seeks training, Sensei.","dojo_2b",[]],
    [anyone|plyr,"dojo_1",
		[
			(neg|check_quest_active,'qst_kengo_training'),
			(troop_get_slot,':training_flag','$g_town_sensei',slot_sensei_flag),
			(assign,':dialog_valid',false),
			(try_begin),
				(call_script,'script_cf_object_flag_set',obj_troop,'trp_player',slot_player_training_flags,':training_flag'),
			(else_try),
				(assign,':dialog_valid',true),
			(try_end),
			(eq,':dialog_valid',true),
			],
     "I wish to follow the path of the kengo.","dojo_2c",[]],
    [anyone,"dojo_2b",[],"Oh? And which of your friends seeks my guidance?","dojo_3b",[]],
    [anyone|plyr|repeat_for_troops,"dojo_3b",
		[
			(store_repeat_object,':troop_no'),
			(is_between,':troop_no','trp_haruko','trp_yamamatsu'),
			(main_party_has_troop,':troop_no'),
			(call_script,"script_companion_training",':troop_no','$g_town_sensei',1),
			(eq,reg0,true),
			(str_store_troop_name,s10,':troop_no'),
			],
     "{s10}","dojo_5b",
	 [(store_repeat_object,"$troop_to_train")]],
    [anyone,"dojo_5b",[(str_store_troop_name,1,"$troop_to_train")],
     "Very well, {s1}. Your training will be painful and grueling, and will last one week. The cost for this is 1440 mon. Is this acceptable?","dojo_6b",[]],
    [anyone|plyr,"dojo_6b",
		[
			(store_troop_gold,reg1,trp_player),
			(ge,reg1,1440),
			],
		"Yes.","dojo_7b",
		[
			(troop_remove_gold,trp_player,1440),
			(store_conversation_troop,':sensei'),
			(store_current_scene,':dojo'),
			(remove_member_from_party,"$troop_to_train"),
			(quest_set_slot,'qst_companion_training',slot_quest_companion_training_dojo,':dojo'),
			(quest_set_slot,'qst_companion_training',slot_quest_companion_training_sensei,':sensei'),
			(quest_set_slot,'qst_companion_training',slot_quest_companion_training_companion,'$troop_to_train'),
			(quest_set_slot,'qst_companion_training',slot_quest_giver,':sensei'),
			(scene_set_slot,':dojo',slot_dojo_sensei_away,1),
			(scene_set_slot,':dojo',slot_dojo_trainee,"$troop_to_train"),
			(scene_set_slot,':dojo',slot_dojo_training,1),
			(str_store_troop_name,10,"$troop_to_train"),
			(str_store_troop_name,11,':sensei'),
			(str_store_party_name,13,'$g_encountered_party'),
			(setup_quest_text,"qst_companion_training"),
			(setup_quest_giver,'qst_companion_training',11),
			(call_script,'script_start_quest',"qst_companion_training"),
			]],
    [anyone|plyr,"dojo_6b",[],"No.","dojo_6",[]],
    [anyone,"dojo_7b",[],"Excellent. Return in a week and your friend's training will be complete.","close_window",[]],
    [anyone,"dojo_2",[],"Very well. However, I do not give my services away. My fee is 360 mon.","dojo_3",[]],
    [anyone|plyr,"dojo_3",[(store_troop_gold,reg1,0),(ge,reg1,360)],"Here is your money, Sensei.","dojo_4",
     [(troop_remove_gold,0,360)]],
    [anyone,"dojo_4",[],"Excellent. Let the training begin. Ippon!","close_window",
     [(assign,"$training_fight_won",0),
      (assign,"$waiting_for_training_fight_result",1),
      (modify_visitors_at_site,"scn_novice_ground"),
      (reset_visitors),
      (assign,reg0,0),
      (assign,reg1,1),
      (assign,reg2,2),
      (assign,reg3,3),
      (shuffle_range,0,4),
      (set_visitor,reg0,"trp_player"),
      (set_visitor,reg1,"trp_sparring_partner"),
      (set_jump_mission,"mt_dojo_training_fight"),
      (jump_to_scene,"scn_novice_ground")]],
    [anyone|plyr,"dojo_3",[(store_troop_gold,reg1,0),(lt,reg1,5)],"I do not have it, Sensei.","dojo_5",[]],
    [anyone|plyr,"dojo_3",[],"Never mind, Sensei.","dojo_6",[]],
    [anyone,"dojo_5",[],"How unfortunate. Financial diligence is also a virtue.","close_window",[]],
    [anyone,"dojo_2c",[],"The path of the Kengo? This is a long and solitary road you seek. It requires the greatest commitment, the most serious mind. Is this truly what you wish?","dojo_3c",[]],
    [anyone|plyr,"dojo_3c",[],"Yes, Sensei. I'm not afraid.","dojo_4c",[]],
    [anyone,"dojo_4c",[(store_conversation_troop,"$g_sensei_trainer"),
					   (str_store_troop_name,s10,'$g_sensei_trainer'),
					   (setup_quest_text,'qst_kengo_training'),
					   (start_quest,'qst_kengo_training'),
					   (quest_set_slot,'qst_kengo_training',slot_quest_giver,'$g_sensei_trainer'),
                       (troop_set_slot,'$g_sensei_trainer',slot_sensei_begin_kengo,1),
                       (troop_set_slot,'$g_sensei_trainer',slot_sensei_difficulty,0),
                       (assign,"$waiting_for_training_fight_result",-1)],
	 "Oh, you will be. You...will be.","close_window",[]],
    [anyone|plyr,"dojo_3c",[],"Perhaps not, Sensei.","dojo_6",[]],
    [anyone,"dojo_6",[(assign,"$troop_to_train",-1)],"As you wish. Good day.","close_window",[]],
#Begin innkeeper dialogs
	[trp_village_38_innkeeper,'start',[(neg|check_quest_active,'qst_subclass_shinobi')],'I do not know you. Please leave.','close_window',[]],
    [trp_village_38_innkeeper,'start',[(check_quest_active,'qst_subclass_shinobi')],'Welcome, young shinobi...','innkeeper_pre_talk',[]],
    [anyone,"start",[(store_conversation_troop,reg1),
                     (is_between,reg1,innkeepers_begin,innkeepers_end)],
     "Greetings, {s1}...","innkeeper_pre_talk",[(troop_get_slot,reg2,"trp_player",slot_player_title),
                                                (str_store_string,1,reg2)]],
    [anyone,"innkeeper_pre_talk",[(store_conversation_troop,reg1),
                                  (troop_get_slot,"$partner_att",reg1,slot_troop_att_to_player)],
     "What can I do for you?","innkeeper_talk_1",[]],
    [anyone|plyr,"innkeeper_talk_1",[(ge,"$partner_att",att_defensive)],
     "I'd like to rest for a while.","innkeeper_rest",[]],
    [anyone|plyr,"innkeeper_talk_1",[(ge,"$partner_att",att_friendly),(neg|check_quest_active,'qst_subclass_monk')],
     "I'd like to hire some troops.","innkeeper_hire",[]],
    [anyone|plyr,"innkeeper_talk_1",[(ge,"$partner_att",att_offensive)],
     "I'd like a drink.","innkeeper_drink",[]],
	[anyone|plyr,'innkeeper_talk_1',
		[
			(check_quest_active,'qst_ronin_investigate_bandit_activity'),
			(quest_slot_eq,'qst_ronin_investigate_bandit_activity',slot_quest_party_1,'$g_encountered_party'),
			],
		"I'm looking into some bandits seen near here. Have you heard anything?",'investigation_innkeeper_1',[]],
	[anyone,'investigation_innkeeper_1',
		[
			(call_script,'script_cf_object_flag_set',obj_quest,'qst_ronin_investigate_bandit_activity',slot_quest_flags,riqf_innkeeper),
			(quest_get_slot,reg20,'qst_ronin_investigate_bandit_activity',slot_quest_flags),
			(display_message,'@Flag value: {reg20}',purple_text),
			],
		"Yeah, I've seen them. Came in here last night, got drunk, harassed my waitress, and passed out in all my rooms. Drove out all the decent customers. The leader did pay, though. He certainly had a lot of money on him.",
		'investigation_complete',
		[
			(call_script,'script_object_set_flag',obj_quest,'qst_ronin_investigate_bandit_activity',slot_quest_flags,riqf_weaponsmith,true),
			]],
	[anyone,'investigation_innkeeper_1',
		[
			(store_attribute_level,':chr_level','trp_player',ca_charisma),
			(val_div,':chr_level',2),
			(store_random_in_range,':roll',0,10),
			(le,':roll',':chr_level'),
			],
		"Yeah, I've seen them. Came in here last night, got drunk, harassed my waitress, and passed out in all my rooms. Drove out all the decent customers. The leader did pay, though. He certainly had a lot of money on him.",
		'investigation_complete',
		[
			(call_script,'script_object_set_flag',obj_quest,'qst_ronin_investigate_bandit_activity',slot_quest_flags,riqf_weaponsmith,true),
			]],
	[anyone,'investigation_innkeeper_1',[],"Sorry, I haven't heard of any bandits around.",'investigation_failed',[]],
    
    [anyone|plyr,"innkeeper_talk_1",[],"Nothing, thanks.","close_window",[]],
    [anyone,"innkeeper_rest",[],
     "Sure, that'll be {reg1} mon for the room. How long do you wish to stay?","innkeeper_rest_2",
		[
			(store_party_size_wo_prisoners,"$g_inn_cost","p_main_party"),
			(val_mul,"$g_inn_cost",5),
			(assign,reg1,'$g_inn_cost'),
			]],
    [anyone|plyr,"innkeeper_rest_2",[(store_troop_gold,':available_cash',"trp_player"),
                                     (ge,':available_cash',"$g_inn_cost"),
                                     (store_time_of_day,reg2),
                                     (val_add,reg2,7),
                                     (val_mod,reg2,24),
                                     (lt,reg2,12)],
     "I would like to stay until morning.","close_window",
		[
			(assign,reg3,13),
			(val_sub,reg3,reg2),
			(troop_remove_gold,"trp_player","$g_inn_cost"),
			(rest_for_hours,reg3),
			(finish_mission,0),
			(change_screen_return,0),
			]],
    [anyone|plyr,"innkeeper_rest_2",[(store_troop_gold,':available_cash',"trp_player"),
                                     (ge,':available_cash',"$g_inn_cost"),
                                     (store_time_of_day,reg2),
                                     (val_add,reg2,7),
                                     (val_mod,reg2,24),
                                     (ge,reg2,12)],
     "I would like to stay until evening.","close_window",
		[
			(assign,reg3,27),
			(val_sub,reg3,reg2),
			(rest_for_hours,reg3),
			(troop_remove_gold,"trp_player","$g_inn_cost"),
			(finish_mission,0),
			(change_screen_return,0),
			]],
    [anyone|plyr,"innkeeper_rest_2",[(store_troop_gold,':available_cash',"trp_player"),
									 (store_mul,':three_day_cost','$g_inn_cost',3),
                                     (ge,':available_cash',":three_day_cost")],
     "I would like to stay for three days.","close_window",
		[
			(val_mul,'$g_inn_cost',3),
			(rest_for_hours,72),
			(troop_remove_gold,"trp_player","$g_inn_cost"),
			(finish_mission,0),
			(change_screen_return,0),
			]],
    [anyone|plyr,"innkeeper_rest_2",[],"Never mind.","innkeeper_pre_talk",[]],
    [anyone,"innkeeper_hire",[],"I know some people who would follow you if you paid for their gear.","innkeeper_hire_2",
		[
			(party_get_slot,':mercs_source','$g_encountered_party',slot_town_mercs),
			(set_mercenary_source_party,':mercs_source'),
			(change_screen_buy_mercenaries,0),
			]],
    [anyone,'innkeeper_hire_2',[],"It'll take some time to gather everyone together. Please wait here.",'innkeeper_pre_talk',[(rest_for_hours,1,4,0)]],
    [anyone,"innkeeper_drink",[],"Sure. That'll be 3 mon.","innkeeper_drink_2",[]],
    [anyone|plyr,"innkeeper_drink_2",[(store_troop_gold,reg2,"trp_player"),
                                      (ge,reg2,3)],
     "Thanks. Here you go.","innkeeper_drink_3",[(troop_remove_gold,"trp_player",3),
                                                 (store_conversation_troop,reg1),
                                                 (troop_get_slot,reg3,reg1,slot_troop_att_to_player),
                                                 (val_add,reg3,1),
                                                 (troop_set_slot,reg1,slot_troop_att_to_player,reg3),
                                                 (troop_get_slot,reg2,reg1,slot_troop_patronage),
                                                 (val_add,reg2,1),
                                                 (troop_set_slot,reg1,slot_troop_patronage,reg2)]],
    [anyone|plyr,"innkeeper_drink_2",[],"Never mind.","innkeeper_drink_3",[]],
    [anyone|plyr,"innkeeper_drink_3",[],"What have you heard?","innkeeper_gossip",[]],
    [anyone|plyr,"innkeeper_drink_3",[],"Thanks again.","close_window",[]],
    [anyone,"innkeeper_gossip",[],"Well, let me tell ya'...","innkeeper_gossip_2",[]],
    [anyone,"innkeeper_gossip_2",[(store_conversation_troop,reg1),
                                  (troop_get_slot,reg2,reg1,slot_troop_gender),
                                  (eq,reg2,0),
                                  (store_random_in_range,reg2,0,4),
                                  (assign,reg3,"str_teahouse1_m"),
                                  (val_add,reg3,reg2),
                                  (str_store_string,1,reg3)],"{s1}","innkeeper_pre_talk",[]],
    [anyone,"innkeeper_gossip_2",[(store_conversation_troop,reg1),
                                  (troop_get_slot,reg2,reg1,slot_troop_gender),
                                  (eq,reg2,1),
                                  (store_random_in_range,reg2,0,4),
                                  (assign,reg3,"str_teahouse1_f"),
                                  (val_add,reg3,reg2),
                                  (str_store_string,1,reg3)],"{s1}","innkeeper_pre_talk",[]],
# Moneychanger dialogs
	[anyone,'start',
		[
			(store_conversation_troop,'$g_conversation_troop'),
			(is_between,'$g_conversation_troop',moneychangers_begin,moneychangers_end),
			],
		'Greetings...','mc_pretalk',[]],
	[anyone,'mc_pretalk',[],'How I can be of service today?','mc_talk1',[]],
	[anyone|plyr,'mc_talk1',[],"I'd like to exchange some coins",'mc_exchange_start',[]],
	[anyone,'mc_exchange_start',[],'What would you like to exchange?','mc_exchange_choose',[]],
	[anyone|plyr|repeat_for_troops,'mc_exchange_choose',
		[
			(store_repeat_object,':dialog_selection'),
			(assign,':dialog_valid',false),
			(is_between,':dialog_selection',0,7),
			(store_sub,':dialog_selection',tc_mc_base,':dialog_selection'),
			(store_troop_gold,':player_gold','trp_player'),
			(try_begin),
				(eq,':dialog_selection',tc_mc_mon_to_string),
				(ge,':player_gold',101),
				(assign,':dialog_valid',true),
				(str_store_string,s10,'@I would like to exchange mon for strings of mon'),
			(else_try),
				(eq,':dialog_selection',tc_mc_mon_to_koban),
				(ge,':player_gold',1085),
				(assign,':dialog_valid',true),
				(str_store_string,s10,'@I would like to exchange mon for koban'),
			(else_try),
				(eq,':dialog_selection',tc_mc_string_to_mon),
				(call_script,'script_troop_get_item_count','trp_player','itm_string_of_coins'),
				(gt,reg0,0),
				(assign,':dialog_valid',true),
				(str_store_string,s10,'@I would like to exchange strings of mon for mon'),
			(else_try),
				(eq,':dialog_selection',tc_mc_koban_to_mon),
				(call_script,'script_troop_get_item_count','trp_player','itm_koban'),
				(gt,reg0,0),
				(assign,':dialog_valid',true),
				(str_store_string,s10,'@I would like to exchange koban for mon'),
			(else_try),
				(eq,':dialog_selection',tc_mc_koban_stack_to_mon),
				(call_script,'script_troop_get_item_count','trp_player','itm_stack_of_koban'),
				(gt,reg0,0),
				(assign,':dialog_valid',true),
				(str_store_string,s10,'@I would like to exchange a stack of koban for mon'),
			(else_try),
				(eq,':dialog_selection',tc_mc_koban_stack_to_koban),
				(call_script,'script_troop_get_item_count','trp_player','itm_stack_of_koban'),
				(gt,reg0,0),
				(assign,':dialog_valid',true),
				(str_store_string,s10,'@I would like to split this stack of koban'),
			(else_try),
				(eq,':dialog_selection',tc_mc_koban_to_koban_stack),
				(call_script,'script_troop_get_item_count','trp_player','itm_koban'),
				(ge,reg0,10),
				(assign,':dialog_valid',true),
				(str_store_string,s10,'@I would like to stack some koban'),
			(try_end),
			(eq,':dialog_valid',true),
			],
		'{s10}','mc_exchange_amount',
		[
			(store_repeat_object,':dialog_selection'),
			(store_sub,':dialog_selection',tc_mc_base,':dialog_selection'),
			(try_begin),
				(eq,':dialog_selection',tc_mc_mon_to_string),
				(assign,'$g_talk_context',tc_mc_mon_to_string),
				(str_store_string,s10,'@I would like to exchange mon for strings of mon'),
			(else_try),
				(eq,':dialog_selection',tc_mc_mon_to_koban),
				(assign,'$g_talk_context',tc_mc_mon_to_koban),
				(str_store_string,s10,'@I would like to exchange mon for koban'),
			(else_try),
				(eq,':dialog_selection',tc_mc_string_to_mon),
				(assign,'$g_talk_context',tc_mc_string_to_mon),
				(str_store_string,s10,'@I would like to exchange strings of mon for mon'),
			(else_try),
				(eq,':dialog_selection',tc_mc_koban_to_mon),
				(assign,'$g_talk_context',tc_mc_koban_to_mon),
				(str_store_string,s10,'@I would like to exchange koban for mon'),
			(else_try),
				(eq,':dialog_selection',tc_mc_koban_stack_to_mon),
				(assign,'$g_talk_context',tc_mc_koban_stack_to_mon),
				(str_store_string,s10,'@I would like to exchange a stack of koban for mon'),
			(else_try),
				(eq,':dialog_selection',tc_mc_koban_stack_to_koban),
				(assign,'$g_talk_context',tc_mc_koban_stack_to_koban),
				(str_store_string,s10,'@I would like to split this stack of koban'),
			(else_try),
				(eq,':dialog_selection',tc_mc_koban_to_koban_stack),
				(assign,'$g_talk_context',tc_mc_koban_to_koban_stack),
				(str_store_string,s10,'@I would like to stack some koban'),
			(try_end),
			]],
	[anyone|plyr,'mc_exchange_choose',[],'Never mind','mc_end',[]],
	[anyone|plyr,'mc_exchange_amount',[],'{s10}','mc_exchange_amount_choose_1',[]],
	[anyone,'mc_exchange_amount_choose_1',
		[
			(str_clear,s10),
			(try_begin),
				(eq,'$g_talk_context',tc_mc_mon_to_string),
				(str_store_string,s10,'@I can exchange 100 mon per string, and my fee is 1%. How much would you like to convert?'),
			(else_try),
				(eq,'$g_talk_context',tc_mc_mon_to_koban),
				(str_store_string,s10,'@I can exchange 1080 mon per gold koban, and my fee is 0.5%. How much would you like to convert?'),
			(else_try),
				(eq,'$g_talk_context',tc_mc_string_to_mon),
				(call_script,'script_troop_get_item_count','trp_player','itm_string_of_coins'),
				(assign,reg10,reg0),
				(assign,reg11,0),
				(try_begin),
					(gt,reg10,1),
					(assign,reg11,1),
				(try_end),
				(str_store_string,s10,'@I can exchange 100 mon per string, and my fee is 1%.'),
				(str_store_string,s10,'@{s10} I see you have {reg10} {reg11?strings:string} of mon.'),
				(str_store_string,s10,'@{s10} How many would you like to convert?'),
			(else_try),
				(eq,'$g_talk_context',tc_mc_koban_to_mon),
				(call_script,'script_troop_get_item_count','trp_player','itm_koban'),
				(assign,reg10,reg0),
				(str_store_string,s10,'@I can exchange 1080 mon per gold koban, and my fee is 0.5%.'),
				(str_store_string,s10,'@{s10} I see you have {reg10} gold koban.'),
				(str_store_string,s10,'@{s10} How many would you like to convert?'),
			(else_try),
				(eq,'$g_talk_context',tc_mc_koban_stack_to_mon),
				(call_script,'script_troop_get_item_count','trp_player','itm_stack_of_koban'),
				(assign,reg10,reg0),
				(str_store_string,s10,'@I can exchange 10800 mon per stack, and my fee is 0.5%.'),
				(str_store_string,s10,'@{s10} I see you have {reg10} gold koban.'),
				(str_store_string,s10,'@{s10} How many would you like to convert?'),
			(else_try),
				(eq,'$g_talk_context',tc_mc_koban_stack_to_koban),
				(call_script,'script_troop_get_item_count','trp_player','itm_stack_of_koban'),
				(assign,reg10,reg0),
				(assign,reg11,0),
				(try_begin),
					(gt,reg10,1),
					(assign,reg11,1),
				(try_end),
				(str_store_string,s10,'@I can exchange 10 koban per stack.'),
				(str_store_string,s10,'@{s10} I see you have {reg10} {reg11?stacks:stack}.'),
				(str_store_string,s10,'@{s10} How many would you like to convert?'),
			(else_try),
				(eq,'$g_talk_context',tc_mc_koban_to_koban_stack),
				(call_script,'script_troop_get_item_count','trp_player','itm_koban'),
				(assign,reg10,reg0),
				(str_store_string,s10,'@I can exchange 10 koban per stack.'),
				(str_store_string,s10,'@{s10} I see you have {reg10} koban.'),
				(str_store_string,s10,'@{s10} How many would you like to convert?'),
			(try_end),
			],
		'{s10}','mc_exchange_amount_choose_2',
		[
			]],
	[anyone|plyr|repeat_for_troops,'mc_exchange_amount_choose_2',
		[
			(store_repeat_object,':exchange_amount'),
			(is_between,':exchange_amount',1,11),
			(store_troop_gold,':player_cash','trp_player'),
			(assign,':selection_valid',false),
			(try_begin),
				(eq,'$g_talk_context',tc_mc_mon_to_string),
				(store_mul,':value_strings_of_mon',':exchange_amount',101),
				(ge,':player_cash',':value_strings_of_mon'),
				(assign,':selection_valid',true),
				(assign,reg10,':exchange_amount'),
				(assign,reg11,':value_strings_of_mon'),
				(assign,reg12,0),
				(try_begin),
					(gt,':exchange_amount',1),
					(assign,reg12,1),
				(try_end),
				(str_store_string,s10,'@{reg11} mon to {reg10} {reg12?strings:string}'),
			(else_try),
				(eq,'$g_talk_context',tc_mc_mon_to_koban),
				(store_mul,':value_koban',':exchange_amount',1085),
				(ge,':player_cash',':value_koban'),
				(assign,':selection_valid',true),
				(assign,reg10,':exchange_amount'),
				(assign,reg11,':value_koban'),
				(str_store_string,s10,'@{reg11} mon to {reg10} koban'),
			(else_try),
				(eq,'$g_talk_context',tc_mc_string_to_mon),
				(call_script,'script_troop_get_item_count','trp_player','itm_string_of_coins'),
				(assign,':num_strings',reg0),
				(le,':exchange_amount',':num_strings'),
				(store_mul,':value_string_of_mon',':num_strings',99),
				(assign,':selection_valid',true),
				(assign,reg10,':value_string_of_mon'),
				(assign,reg11,':exchange_amount'),
				(assign,reg12,0),
				(try_begin),
					(gt,':exchange_amount',1),
					(assign,reg12,1),
				(try_end),
				(str_store_string,s10,'@{reg11} {reg12?strings:string} of mon'),
			(else_try),
				(eq,'$g_talk_context',tc_mc_koban_to_mon),
				(call_script,'script_troop_get_item_count','trp_player','itm_koban'),
				(assign,':num_koban',reg0),
				(le,':exchange_amount',':num_koban'),
				(store_mul,':value_koban',':exchange_amount',1075),
				(assign,':selection_valid',true),
				(assign,reg10,':value_koban'),
				(assign,reg11,':exchange_amount'),
				(str_store_string,s10,'@{reg11} koban to {reg10} mon'),
			(else_try),
				(eq,'$g_talk_context',tc_mc_koban_stack_to_mon),
				(call_script,'script_troop_get_item_count','trp_player','itm_stack_of_koban'),
				(assign,':num_stacks',reg0),
				(le,':exchange_amount',':num_stacks'),
				(store_mul,':value_stacks',':num_stacks',10750),
				(assign,':selection_valid',true),
				(assign,reg10,':value_stacks'),
				(assign,reg11,':exchange_amount'),
				(assign,reg12,0),
				(try_begin),
					(gt,':exchange_amount',1),
					(assign,reg12,1),
				(try_end),
				(str_store_string,s10,'@{reg11} {reg12?stacks:stack} of koban'),
			(else_try),
				(eq,'$g_talk_context',tc_mc_koban_stack_to_koban),
				(call_script,'script_troop_get_item_count','trp_player','itm_stack_of_koban'),
				(assign,':num_stacks',reg0),
				(eq,':num_stacks',':exchange_amount'),
				(store_mul,':value_stacks',':num_stacks',10),
				(assign,':selection_valid',true),
				(assign,reg10,':value_stacks'),
				(assign,reg11,':exchange_amount'),
				(assign,reg12,0),
				(try_begin),
					(gt,':exchange_amount',1),
					(assign,reg12,1),
				(try_end),
				(str_store_string,s10,'@{reg11} {reg12?stacks:stack} of koban'),
			(else_try),
				(eq,'$g_talk_context',tc_mc_koban_to_koban_stack),
				(call_script,'script_troop_get_item_count','trp_player','itm_koban'),
				(assign,':num_koban',reg0),
				(store_mul,':num_koban_per_stack',':exchange_amount',10),
				(ge,':num_koban',':num_koban_per_stack'),
				(store_div,':value_stacks',':num_koban',10),
				(assign,':selection_valid',true),
				(assign,reg10,':value_stacks'),
				(assign,reg11,':exchange_amount'),
				(assign,reg12,0),
				(try_begin),
					(gt,':exchange_amount',1),
					(assign,reg12,1),
				(try_end),
				(str_store_string,s10,'@{reg11} koban'),
			(try_end),
			(eq,':selection_valid',true),
			],
		'{s10}','mc_make_exchange',
		[
			(store_repeat_object,':exchange_amount'),
			(try_begin),
				(eq,'$g_talk_context',tc_mc_mon_to_string),
				(store_mul,':exchange_value',':exchange_amount',101),
				(troop_remove_gold,'trp_player',':exchange_value'),
				(troop_add_items,'trp_player','itm_string_of_coins',':exchange_amount'),
			(else_try),
				(eq,'$g_talk_context',tc_mc_mon_to_koban),
				(store_mul,':exchange_value',':exchange_amount',1085),
				(troop_remove_gold,'trp_player',':exchange_value'),
				(troop_add_items,'trp_player','itm_koban',':exchange_amount'),
			(else_try),
				(eq,'$g_talk_context',tc_mc_string_to_mon),
				(store_mul,':exchange_value',':exchange_amount',99),
				(troop_remove_items,'trp_player','itm_string_of_coins',':exchange_amount'),
				(troop_add_gold,'trp_player',':exchange_value'),
			(else_try),
				(eq,'$g_talk_context',tc_mc_koban_to_mon),
				(store_mul,':exchange_value',':exchange_amount',1075),
				(troop_remove_items,'trp_player','itm_koban',':exchange_amount'),
				(troop_add_gold,'trp_player',':exchange_value'),
			(else_try),
				(eq,'$g_talk_context',tc_mc_koban_stack_to_mon),
				(store_mul,':exchange_value',':exchange_amount',10750),
				(troop_remove_items,'trp_player','itm_stack_of_koban',':exchange_amount'),
				(troop_add_gold,'trp_player',':exchange_value'),
			(else_try),
				(eq,'$g_talk_context',tc_mc_koban_to_koban_stack),
				(store_mul,':exchange_value',':exchange_amount',10),
				(troop_remove_items,'trp_player','itm_koban',':exchange_value'),
				(troop_add_items,'trp_player','itm_stack_of_koban',':exchange_amount'),
			(else_try),
				(eq,'$g_talk_context',tc_mc_koban_stack_to_koban),
				(store_mul,':exchange_value',':exchange_amount',10),
				(troop_remove_items,'trp_player','itm_stack_of_koban',':exchange_amount'),
				(troop_add_items,'trp_player','itm_koban',':exchange_value'),
			(try_end),
			]],
	[anyone,'mc_make_exchange',[],'Very good. The exchange is complete.','mc_exchange_complete',[]],
	[anyone|plyr,'mc_exchange_complete',[],"Excellent. It's been a pleasure",'mc_pretalk',[]],
	[anyone|plyr,'mc_talk1',[],'Never mind.','mc_end',[]],
	[anyone,'mc_end',[],'Very well. Good day.','close_window',[]],
#Slaver dialogs
    [trp_hyogo_slaver,"start",[(store_conversation_troop,reg1),
                               (troop_get_slot,reg2,reg1,slot_troop_intro),
                               (gt,reg2,0)],
     "So, are you ready to do business?","sell_prisoners",[]],
    [trp_tsuruga_slaver,"start",[],"So, are you ready to do business?","sell_prisoners",[]],
    [trp_mitsue_slaver,"start",[],"So, are you ready to do business?","sell_prisoners",[]],
    [anyone|plyr,"sell_prisoners",
		[
			(party_get_num_prisoners,reg1,'p_main_party'),
			(party_set_slot,'p_main_party',slot_main_prisoners,reg1),
			],
		"I am. Let's deal.","sell_prisoners_2",
		[
			(change_screen_trade_prisoners),
			]],
    [anyone|plyr,"sell_prisoners",[],"Another time, perhaps.","sell_prisoners_3",[]],
    [anyone,"sell_prisoners_2",
		[
			(party_get_num_prisoners,':current_prisoners','p_main_party'),
			(party_get_slot,':prev_prisoners','p_main_party',slot_main_prisoners),
			(store_sub,':num_prisoners_sold',':prev_prisoners',':current_prisoners'),
			(val_mul,':num_prisoners_sold',360),
			(troop_add_gold,0,':num_prisoners_sold'),
			],
		"I hope to do business with you again soon.","close_window",[]],
    [anyone,"sell_prisoners_3",[],"I'll be waiting.","close_window",[]],
    
    [trp_hyogo_slaver,"start",[(store_conversation_troop,reg1),
                               (troop_get_slot,reg2,reg1,slot_troop_intro),
                               (lt,reg2,1)],
      "Good day to you, {Tono/Hime}. Would you be interested in a lucrative proposition?","sell_prisoners_pre_talk",[]],
    [anyone|plyr,"sell_prisoners_pre_talk",[],"Perhaps. I'm listening.","sell_prisoners_pre_talk_2",[]],
    [anyone,"sell_prisoners_pre_talk_2",[],"I represent various interests that require the use of strong manual labor. Naturally, such a resource is difficult to find.","sell_prisoners_pre_talk_3",[]],
    [anyone|plyr,"sell_prisoners_pre_talk_3",[],"Slavery, you mean.","sell_prisoners_pre_talk_4",[]],
    [anyone,"sell_prisoners_pre_talk_4",[],"More like indentured servitude. I can offer you a full koku per head, plus a 20 mon finder's fee. Our operations are fully backed by the Shogun as punishment for various criminals.","sell_prisoners_pre_talk_5",[]],
    [anyone|plyr,"sell_prisoners_pre_talk_5",[],"Indeed. There are enough of those around. I will consider your proposal.",
     "sell_prisoners_pre_talk_6",[(store_conversation_troop,reg1),
                                  (troop_set_slot,reg1,slot_troop_intro,1)]],
    [anyone,"sell_prisoners_pre_talk_6",[],"Such is all I ask, {Tono/Hime}. Good day.","close_window",[]],

#Disciple dialogs
    [trp_hyogo_disciple,"start",
		[
			(check_quest_active,'qst_subclass_kengo'),
			(str_store_string,s10,'@Master'),
			],
		"I have sought long for you, {s10} {playername}.","disciple_talk",[]],
    [trp_hyogo_disciple,"start",[(main_party_has_troop,"trp_yamamatsu")],"I have sought long for you, Master Yamamatsu.","disciple_talk",[]],
    [trp_hyogo_disciple,"start",[],"Though you may be a learned swordmaster, you are not who I seek.","close_window",[]],
    [anyone,"disciple_talk",[],"How may I be of service?","disciple_talk_2",[]],
    [anyone|plyr,"disciple_talk_2",[],"I'm looking to take on some students.","hire_disciples",[]],
    [anyone|plyr,"disciple_talk_2",[],"What news have you?","disciple_news",[]],
    [anyone|plyr,"disciple_talk_2",[],"Nothing for now.","disciple_end",[]],
    [anyone,"hire_disciples",[],"I know some young men eager to study under you, Sensei.","disciple_talk",[(set_mercenary_source_party,"p_hyogo_disciples"),[change_screen_buy_mercenaries]]],
    [anyone,"disciple_news",[],"I am sorry, Sensei. I have heard nothing.","disciple_talk",[]],
    [anyone,"disciple_end",[],"I will await your return.","close_window",[]],
#Kokujin dialogs
    [anyone,"start",
		[
			(store_conversation_troop,'$g_conversation_troop'),
			(neq,'$g_conversation_troop',trp_village_2_kokujin),
			(eq,'$g_conversation_troop','$g_town_kokujin'),
			],
		"Greetings...","kokujin_start",
		[
			(try_begin),
			(this_or_next|eq,'$g_encountered_party',akashi),
			(this_or_next|eq,'$g_encountered_party',misaki),
			(this_or_next|eq,'$g_encountered_party',iwaji),
			(eq,'$g_encountered_party',sumoto),
			(assign,"$teleport_city",1),
			(else_try),
			(assign,"$teleport_city",0),
			(try_end),
			]],
    [anyone,"kokujin_start",
     [
         (str_store_troop_name,2,'$g_conversation_troop'),
         (str_store_party_name,3,'$g_encountered_party'),
         ],
     "I am {s2}, administrator of {s3}.","admin_pre_talk",[]],
    [anyone,"admin_pre_talk",[],"How can I help you?","admin_talk_1",[]],
	[anyone|plyr,"admin_talk_1",[],"What day is it?","current_date",[]],
	[anyone|plyr,'admin_talk_1',[(neg|check_quest_active,'qst_subclass_shinobi'),
								(neg|check_quest_active,'qst_subclass_monk'),
								(store_conversation_troop,reg1),
								(eq,reg1,'trp_village_38_kokujin')],
		'I heard this is the village of the Shinobi.','admin_shinobi_start',[]],
	[anyone,'admin_shinobi_start',[],'Yeah, what of it?','admin_shinobi_1',[]],
	[anyone|plyr,'admin_shinobi_1',[],'Sh1nob1 r t0t4lly $w33t! They fly 4round and k1ll p30pl3. ! w4nn4 be a L33T n1nj4!','admin_shinobi_join',[]],
	[anyone,'admin_shinobi_join',[(start_quest,'qst_subclass_shinobi')],'Kid, with that attitude, sure! You can hire extra troops at the inn.','close_window',[]],
    [anyone|plyr,'admin_talk_1',[],'What is the status of this town?','town_status',[]],
    [anyone,'town_status',
     [
         (party_get_num_companions,reg1,'$g_encountered_party'),
         (party_get_slot,reg2,'$g_encountered_party',slot_town_treasury),
         (party_get_slot,':garrison_source','$g_encountered_party',slot_town_garrison_source),
         (party_get_num_companions,reg3,':garrison_source'),
         (party_get_slot,reg4,'$g_encountered_party',slot_town_att_to_player),
		 (party_get_slot,reg5,'$g_encountered_party',slot_town_spawn_points),
		 (party_get_slot,reg6,'$g_encountered_party',slot_town_food_stores),
		 (party_get_slot,reg7,'$g_encountered_party',slot_town_accumulated_tariffs),
		 (party_get_slot,reg8,'$g_encountered_party',slot_town_population),
         ],
     "Our town's population is {reg8}, and our town's garrison currently stands at {reg1} souls strong, and our current account stands at {reg2} mon. Our garrison draws from {reg3} men. Our attitude towards you is {reg4}. We have {reg5} points available to muster patrols with. Our foods stores currently stand at {reg6}. We have collected {reg7} mon so far in taxes.",'town_status_2',
	 []],
	[anyone,'town_status_2',
		[
			(str_clear,s10),
			(party_get_slot,':goods_demand_array','$g_encountered_party',slot_town_demand_array),
			(try_for_range,':item_no',trade_goods_begin,trade_goods_end),
				(store_sub,':array_index',':item_no',trade_goods_begin),
				(call_script,'script_array_peek',':goods_demand_array',':array_index'),
				(assign,':item_no_demand_qty','$return'),
				(gt,':item_no_demand_qty',0),
				(str_store_item_name,s11,':item_no'),
				(assign,reg10,':item_no_demand_qty'),
				(str_store_string,s10,'@{s10}{s11} demand: {reg10}; '),
			(try_end),
			],
		'Our demands:^^{s10}','town_status_3',[]],
	[anyone,'town_status_3',
		[
			(str_clear,s10),
			(party_get_slot,':storehouse_array','$g_encountered_party',slot_town_storehouse_array),
			(party_get_slot,':facility_array','$g_encountered_party',slot_town_facility_array),
			(party_get_slot,':num_facilities',':facility_array',array_value_high_index),
			(str_store_string,s10,'@Facilities:^'),
			(try_for_range,':array_index',0,':num_facilities'),
				(call_script,'script_array_peek',':facility_array',':array_index'),
				(assign,':cur_facility','$return'),
				(party_get_slot,':name',':cur_facility',slot_facility_name),
				(str_store_string,s11,':name'),
				(str_store_string,s10,'@{s10}{s11}; '),
			(try_end),
			(str_store_string,s10,'@{s10}^'),
			(str_store_string,s10,'@{s10}Storehouse:^'),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_peek',':storehouse_array',':array_index'),
				(assign,':item_qty','$return'),
				(gt,':item_qty',0),
				(store_add,':item_no',trade_goods_begin,':array_index'),
				(str_store_item_name,s11,':item_no'),
				(assign,reg12,':item_qty'),
				(str_store_string,s10,'@{s10}{s11}: {reg12}, '),
			(try_end),
			],
		'{s10}','town_status_4',
		[
			]],
	[anyone,'town_status_4',
		[
			(str_clear,s10),
			(call_script,'script_update_town_surplus','$g_encountered_party'),
			(party_get_slot,':surplus_array','$g_encountered_party',slot_town_surplus_array),
			(str_store_string,s10,'@Surplus goods:^'),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_peek',':surplus_array',':array_index'),
				(assign,':item_qty','$return'),
				(gt,':item_qty',0),
				(store_add,':item_no',trade_goods_begin,':array_index'),
				(str_store_item_name,s11,':item_no'),
				(assign,reg12,':item_qty'),
				(str_store_string,s10,'@{s10}{s11}: {reg12}, '),
			(try_end),
			# (str_clear,s10),
			# (party_get_slot,':population','$g_encountered_party',slot_town_population),
			# (party_get_slot,':facility_array','$g_encountered_party',slot_town_facility_array),
			# (party_get_slot,':storehouse_array','$g_encountered_party',slot_town_storehouse_array),
			# (call_script,'script_clear_temp_array','trp_temp_array_a',num_trade_goods),
			# (str_store_string,s10,'@Raw demand:^'),
			# (try_for_range,':array_index',0,num_trade_goods),
				# (store_add,':item_no',':array_index',trade_goods_begin),
				# (call_script,'script_calculate_item_demand',':item_no',':population'),
				# (assign,':item_demand',reg0),
				# (call_script,'script_object_modify_slot',obj_troop,'trp_temp_array_a',':array_index',op_add,':item_demand'),
			# (try_end),
			# (party_get_slot,':num_facilities',':facility_array',array_value_high_index),
			# (try_for_range,':facility_array_index',0,':num_facilities'),
				# (call_script,'script_array_peek',':facility_array',':facility_array_index'),
				# (assign,':cur_facility','$return'),
				# (party_get_slot,':facility_demand_array',':cur_facility',slot_facility_inputs_array),
				# (try_for_range,':fda_index',0,num_trade_goods),
					# (call_script,'script_array_peek',':facility_demand_array',':fda_index'),
					# (assign,':facility_demand','$return'),
					# (call_script,'script_object_modify_slot',obj_troop,'trp_temp_array_a',':fda_index',op_add,':facility_demand'),
				# (try_end),
			# (try_end),
			# (try_for_range,':temp_array_index',0,num_trade_goods),
				# (call_script,'script_array_peek',':storehouse_array',':temp_array_index'),
				# (assign,':storehouse_qty','$return'),
				# (store_add,':item_no',':temp_array_index',trade_goods_begin),
				# (troop_get_slot,':demand_qty','trp_temp_array_a',':temp_array_index'),
				# (eq,':demand_qty',0),
				# (gt,':storehouse_qty',0),
				# (assign,reg10,':storehouse_qty'),
				# (str_store_item_name,s11,':item_no'),
				# (str_store_string,s10,'@{s10} {s11} surplus: {reg10}, '),
			# (try_end),
			],
		'{s10}','admin_talk_1',[]],
	[anyone|plyr,'admin_talk_1',[],'Send out a caravan','admin_send_caravan',
		[
			(call_script,'script_cf_town_generate_caravan','$g_encountered_party',tcs_opt_deliver_goods),
			]],
	[anyone,'admin_send_caravan',[],'What a good idea...','admin_talk_1',[]],
	[anyone|plyr,'admin_talk_1',
		[
			(check_quest_active,'qst_ronin_investigate_bandit_activity'),
			(quest_slot_eq,'qst_ronin_investigate_bandit_activity',slot_quest_party_1,'$g_encountered_party'),
			],
		"I'm looking to some bandits seen near here. Have you heard anything?",'investigation_kokujin_1',[]],
	[anyone,'investigation_kokujin_1',
		[
			(call_script,'script_cf_object_flag_set',obj_quest,'qst_ronin_investigate_bandit_activity',slot_quest_flags,riqf_kokujin),
			# (call_script,'script_get_flag_bit',reg20,4),
			# (eq,reg0,1),
			],
		"Yes, actually. Several of the villagers have mentioned seeing them not to long ago.",
		'investigation_complete',
		[
			(call_script,'script_object_set_flag',obj_quest,'qst_ronin_investigate_bandit_activity',slot_quest_flags,riqf_merchant,true),
			# (call_script,'script_set_flag_bit',reg20,1,1),
			# (quest_set_slot,'qst_ronin_investigate_bandit_activity',slot_quest_flags,reg0),
			]],
	[anyone,'investigation_kokujin_1',
		[
			(store_attribute_level,':chr_level','trp_player',ca_charisma),
			(val_div,':chr_level',2),
			(store_random_in_range,':roll',0,10),
			# (display_message,'@{reg1} / 10',purple_text),
			(le,':roll',':chr_level'),
			],
		"Yes, actually. Several of the villagers have mentioned seeing them not to long ago.",
		'investigation_complete',
		[
			(call_script,'script_object_set_flag',obj_quest,'qst_ronin_investigate_bandit_activity',slot_quest_flags,riqf_merchant,true),
			# (quest_set_slot,'qst_ronin_investigate_bandit_activity',slot_quest_flags,'$return'),
			]],
	[anyone,'investigation_kokujin_1',[],"Sorry, I haven't heard of any bandits around.",'investigation_failed',[]],
    [anyone|plyr,"admin_talk_1",
     [
         (eq,"$teleport_city",1),
         (try_begin),
             (eq,'$g_encountered_party',akashi),
             (assign,"$teleport_target",iwaji),
         (else_try),
             (eq,'$g_encountered_party',iwaji),
             (assign,"$teleport_target",akashi),
         (else_try),
             (eq,'$g_encountered_party',misaki),
             (assign,"$teleport_target",sumoto),
         (else_try),
             (eq,'$g_encountered_party',sumoto),
             (assign,"$teleport_target",misaki),
         (try_end),
         (str_store_party_name,1,"$teleport_target")],
     "I'd like to go to {s1}.","teleport",[]],
    [anyone,"teleport",[(party_relocate_near_party,"p_main_party","$teleport_target",1),
                        (str_store_party_name,1,"$teleport_target")],
     "Very well. Enjoy your stay in {s1}.","close_window",[]],
	[anyone|plyr,'admin_talk_1',
		[
			(check_quest_active,'qst_merchant_establish_trading_post'),
			(quest_slot_eq,'qst_merchant_establish_trading_post',slot_quest_target_troop,'$g_conversation_troop'),
			],
		"I'd like to discuss opening up trading post.",'tp_negotiation_begin',[]],
	[anyone,'tp_negotiation_begin',[(eq,'$g_num_negotiation_attempts',3)],'No. I have heard enough from you.','tp_terms_rejected',[]],
	[anyone,'tp_negotiation_begin',[(lt,'$g_num_negotiation_attempts',3)],'Oh? What do you propose?','tp_negotiation_terms',[]],
	[anyone|plyr|repeat_for_troops,'tp_negotiation_terms',
		[
			(store_repeat_object,'$g_tp_fee'),
			(this_or_next|eq,'$g_tp_fee',5),
			(this_or_next|eq,'$g_tp_fee',7),
			(this_or_next|eq,'$g_tp_fee',9),
			(this_or_next|eq,'$g_tp_fee',10),
			(this_or_next|eq,'$g_tp_fee',15),
			(eq,'$g_tp_fee',20),
			(assign,'$g_base_chance',20),
			(try_begin),
				(this_or_next|eq,'$g_tp_fee',5),
				(this_or_next|eq,'$g_tp_fee',7),
				(eq,'$g_tp_fee',9),
				(val_mul,'$g_tp_fee',10),
				(assign,'$g_tp_fee_type',tp_flat_fee),
				(store_random_in_range,':tp_time_type',0,2),
				(assign,reg10,'$g_tp_fee'),
				(str_store_string,s10,'@A flat fee of {reg10} mon,'),
				(assign,':chance_mod','$g_tp_fee'),
				(val_mod,':chance_mod',2),
				(val_sub,'$g_base_chance',':chance_mod'),
			(else_try),
				(this_or_next|eq,'$g_tp_fee',10),
				(this_or_next|eq,'$g_tp_fee',15),
				(eq,'$g_tp_fee',20),
				(assign,'$g_tp_fee_type',tp_percentage_fee),
				(store_random_in_range,':tp_time_type',1,3),
				(assign,reg10,'$g_tp_fee'),
				(str_store_string,s10,'@A percentage of total revenues equaling {reg10}%,'),
				(assign,':chance_mod','$g_tp_fee'),
				(val_mod,':chance_mod',2),
				(val_sub,'$g_base_chance',':chance_mod'),
			(try_end),
			(try_begin),
				(eq,':tp_time_type',0),
				(str_store_string,s12,'@weekly'),
				(assign,'$g_tp_hours',168),
			(else_try),
				(eq,':tp_time_type',1),
				(str_store_string,s12,'@biweekly'),
				(val_mul,'$g_tp_fee',10),
				(val_sub,'$g_base_chance',1),
				(assign,'$g_tp_hours',338),
			(else_try),
				(eq,':tp_time_type',2),
				(str_store_string,s12,'@monthly'),
				(assign,'$g_tp_hours',720),
			(try_end),
			(str_store_string,s11,'@{s10} deposited {s12}.'),
			],
		'{s11}','tp_considering_terms',
		[
			(store_repeat_object,'$g_tp_fee'),
			]],
	[anyone,'tp_considering_terms',[],'Interesting...','tp_terms_considered',
		[
			(store_skill_level,':trade',skl_trade,'trp_player'),
			(store_skill_level,':persuasion',skl_persuasion,'trp_player'),
			(store_attribute_level,':charisma','trp_player',ca_charisma),
			(store_add,'$g_player_persuasive_ability',':charisma',':persuasion'),
			(val_add,'$g_player_persuasive_ability',':trade'),
			(store_random_in_range,'$g_persuasion_chance',0,'$g_base_chance'),
			]],
	[anyone,'tp_terms_considered',
		[
			(ge,'$g_player_persuasive_ability','$g_persuasion_chance'),
			],
		'I accept your terms.','tp_terms_accepted',[]],
	[anyone,'tp_terms_considered',
		[
			(lt,'$g_player_persuasive_ability','$g_base_chance'),
			],
		'I find your terms unacceptable.','tp_terms_rejected',[]],
	[anyone|plyr,'tp_terms_accepted',[],"Excellent! I'll have the necessary papers drawn up. It's been a pleasure doing business.",'tp_start_tp',
		[
			(call_script,'script_initialize_trading_post','$g_encountered_party','trp_player','$g_tp_hours','$g_tp_fee_type','$g_tp_fee'),
			(call_script,'script_succeed_quest','qst_merchant_establish_trading_post'),
			]],
	[anyone,'tp_start_tp',[],'Likewise, {playername}. Good day to you.','close_window',[]],
	[anyone|plyr,'tp_terms_rejected',[(lt,'$g_num_negotiation_attempts',3)],'Perhaps a different set of terms?','tp_negotiation_begin',[(val_add,'$g_num_negotiation_attempts',1)]],
	[anyone|plyr,'tp_terms_rejected',[],'That is unfortunate. I had hoped we could do business together.','tp_end',
		[
			(call_script,'script_fail_quest','qst_merchant_establish_trading_post'),
			]],
	[anyone,'tp_end',[],'It was not meant to be so. Good day, {playername}.','close_window',[]],
	[anyone|plyr,'admin_talk_1',
		[
			(check_quest_active,'qst_merchant_negotiate_trade_contract'),
			# (quest_slot_eq,'qst_merchant_establish_trading_post',slot_quest_target_party,'$g_encountered_party'),
			(quest_slot_eq,'qst_merchant_negotiate_trade_contract',slot_quest_target_troop,'$g_conversation_troop'),
			],
		"I'd like to speak with you about opening up a new trade route.",'new_trade_dest_begin',[]],
	[anyone,'new_trade_dest_begin',[],'Really? That would be beneficial. What are you proposing?','trade_dest_select',[]],
	[anyone|plyr|repeat_for_parties,'trade_dest_select',
		[
			(store_repeat_object,'$g_selected_town'),
			(this_or_next|party_slot_eq,'$g_selected_town',slot_town_size,ct_city),
			(this_or_next|party_slot_eq,'$g_selected_town',slot_town_size,ct_large_town),
			(party_slot_eq,'$g_selected_town',slot_town_size,ct_port),
			(call_script,'script_cf_party_in_range_of_party','$g_encountered_party','$g_selected_town',200),
			(call_script,'script_party_trades_with_party','$g_encountered_party','$g_selected_town'),
			(eq,reg0,false),
			(try_begin),
				(party_slot_eq,'$g_selected_town',slot_town_size,ct_port),
				(assign,'$g_persuasion_bonus',0),
			(else_try),
				(party_slot_eq,'$g_selected_town',slot_town_size,ct_city),
				(assign,'$g_persuasion_bonus',1),
			(else_try),
				(party_slot_eq,'$g_selected_town',slot_town_size,ct_large_town),
				(assign,'$g_persuasion_bonus',2),
			(try_end),
			(str_store_party_name,s11,'$g_selected_town'),
			],
		'{s11}','trade_dest_consider',
		[
			(store_repeat_object,'$g_selected_town'),
			]],
	[anyone,'trade_dest_consider',[],'An interesting suggestion...but what is your involvement?','trade_dest_player_benefit',[]],
	[anyone|plyr|repeat_for_troops,'trade_dest_player_benefit',
		[
			(store_repeat_object,'$g_trade_benefit'),
			(is_between,'$g_trade_benefit',0,3),
			(try_begin),
				(eq,'$g_trade_benefit',0),
				(val_add,'$g_persuasion_bonus',-2),
				(str_store_string,10,"@None, except for a small finder's fee per transaction."),
			(else_try),
				(eq,'$g_trade_benefit',1),
				(val_add,'$g_persuasion_bonus',-1),
				(str_store_string,10,"@None, except for a small percentage of the gross."),
			(else_try),
				(eq,'$g_trade_benefit',2),
				(val_add,'$g_persuasion_bonus',0),
				(str_store_string,10,"@My partners and I would be willing to manage this venture."),
			(try_end),
			],
		'{s10}','trade_dest_fee_negotiation',
		[
			(store_repeat_object,'$g_trade_benefit'),
			]],
	[anyone,'trade_dest_fee_negotiation',
		[
			(try_begin),
				(eq,'$g_trade_benefit',0),
				(str_store_string,12,"@And how much is this fee?"),
			(else_try),
				(eq,'$g_trade_benefit',1),
				(str_store_string,12,"@And what would be the percentage?"),
			(else_try),
				(eq,'$g_trade_benefit',2),
				(str_store_string,12,"@And what would management cost me?"),
			(try_end),
			],
		'{s12}','trade_dest_fee_schedule',[]],
	[anyone|plyr|repeat_for_troops,'trade_dest_fee_schedule',
		[
			(store_repeat_object,'$g_trade_fee'),
			(str_clear,s10),
			(is_between,'$g_trade_fee',0,3),
			(try_begin),
				(eq,'$g_trade_benefit',0),
				(try_begin),
					(eq,'$g_trade_fee',0),
					(assign,'$g_trade_fee',5),
					(val_add,'$g_persuasion_bonus',0),
					(str_store_string,s10,"@5 gold koban."),
				(else_try),
					(eq,'$g_trade_fee',1),
					(assign,'$g_trade_fee',10),
					(val_add,'$g_persuasion_bonus',1),
					(str_store_string,s10,"@10 gold koban."),
				(else_try),
					(eq,'$g_trade_fee',2),
					(assign,'$g_trade_fee',25),
					(val_add,'$g_persuasion_bonus',2),
					(str_store_string,s10,"@25 gold koban."),
				(try_end),
			(else_try),
				(eq,'$g_trade_benefit',1),
				(try_begin),
					(eq,'$g_trade_fee',0),
					(assign,'$g_trade_fee',2),
					(val_add,'$g_persuasion_bonus',0),
					(str_store_string,s10,"@2% of the gross."),
				(else_try),
					(eq,'$g_trade_fee',1),
					(assign,'$g_trade_fee',5),
					(val_add,'$g_persuasion_bonus',1),
					(str_store_string,s10,"@5% of the gross."),
				(else_try),
					(eq,'$g_trade_fee',2),
					(assign,'$g_trade_fee',7),
					(val_add,'$g_persuasion_bonus',2),
					(str_store_string,s10,"@7% of the gross."),
				(try_end),
			(try_begin),
				(eq,'$g_trade_benefit',2),
				(try_begin),
					(eq,'$g_trade_fee',0),
					(assign,'$g_trade_fee',20),
					(val_add,'$g_persuasion_bonus',0),
					(str_store_string,s10,"@20% of the gross."),
				(else_try),
					(eq,'$g_trade_fee',1),
					(assign,'$g_trade_fee',35),
					(val_add,'$g_persuasion_bonus',1),
					(str_store_string,s10,"@35% of the gross."),
				(else_try),
					(eq,'$g_trade_fee',2),
					(assign,'$g_trade_fee',50),
					(val_add,'$g_persuasion_bonus',3),
					(str_store_string,s10,"@50% of the gross."),
				(try_end),
			(try_end),
			],
		'{s10}','trade_fee_consider',
		[
			#(store_repeat_object,'$g_trade_fee'),
			(assign,'$g_base_chance',30),
			(val_add,'$g_base_chance','$g_persuasion_bonus'),
			(store_random_in_range,'$g_persuasion_chance',0,'$g_base_chance'),
			(val_add,'$g_persuasion_chance','$g_persuasion_bonus'),
			(store_skill_level,':trade',skl_trade,'trp_player'),
			(store_skill_level,':persuasion',skl_persuasion,'trp_player'),
			(store_attribute_level,':charisma','trp_player',ca_charisma),
			(store_add,'$g_player_persuasive_ability',':charisma',':persuasion'),
			(val_add,'$g_player_persuasive_ability',':trade'),
			]],
	[anyone,'trade_fee_consider',
		[
			(gt,'$g_player_persuasive_ability','$g_persuasion_chance'),
			],
		'I accept your offer.','trade_dest_initialize',[]],
	[anyone,'trade_fee_consider',
		[
			(le,'$g_player_persuasive_ability','$g_persuasion_chance'),
			],
		'I find your offer unacceptable.','trade_dest_negotiation_failure',[]],
	[anyone|plyr,'trade_dest_initialize',[],"Excellent! I will make the necessary arrangements. It's been a pleasure doing business with you.",'trade_dest_end_success',
		[
			(call_script,'script_succeed_quest','qst_merchant_negotiate_trade_contract'),
			(call_script,'script_init_quest_trade_dest','$g_encountered_party','$g_selected_town','$g_trade_benefit','$g_trade_fee'),
			]],
	[anyone,'trade_dest_end_success',[],'And also with you, {playername}. Good day to you.','close_window',[]],
	[anyone|plyr,'trade_dest_negotiation_failure',
		[
			(lt,'$g_num_negotiation_attempts',3),
			],
		'Perhaps another set of terms?','new_trade_dest_begin',[]],
	[anyone|plyr,'trade_dest_negotiation_failure',
		[
			(eq,'$g_num_negotiation_attempts',3),
			],
		'That is unfortunate. I had hoped we could do business together','trade_dest_end_fail',
		[
			(call_script,'script_fail_quest','qst_merchant_negotiate_trade_contract'),
			]],
	[anyone,'trade_dest_end_fail',[],'It was not meant to be. Good day, {playername}','close_window',[]],
	[anyone|plyr,"admin_talk_1",
		[
			(call_script,'script_cf_get_partner_quest',"$g_conversation_troop"),
			(assign,"$g_kokujin_quest_check",reg0),
			],
     "About that job you gave me...","admin_check_quest",[]],
    [anyone,"admin_check_quest",[],"Yes, what about it?","admin_check_quest_2",[]],
    [anyone|plyr,"admin_check_quest_2",
		[
			(assign,':dialog_valid',false),
			(try_begin),
				(eq,"$g_kokujin_quest_check","qst_kokujin_needs_goods"),
				(str_clear,s11),
				(party_get_slot,':demand_array','$g_encountered_party',slot_town_demand_array),
				(call_script,'script_clear_temp_array','trp_temp_array_a',num_trade_goods),
				# map player's inventory to a temp array using the economy format
				(troop_get_inventory_capacity,':inv_cap','trp_player'),
				(try_for_range,':inv_slot',0,':inv_cap'),
					(troop_get_inventory_slot,':item_no','trp_player',':inv_slot'),
					(is_between,':item_no',trade_goods_begin,trade_goods_end),
					(store_sub,':temp_array_index',':item_no',trade_goods_begin),
					(call_script,'script_object_modify_slot',obj_troop,'trp_temp_array_a',':temp_array_index',op_add,1),
				(try_end),
				# check temp array against town demands
				(try_for_range,':array_index',0,num_trade_goods),
					(call_script,'script_array_peek',':demand_array',':array_index'),
					(assign,':itm_qty_demanded','$return'),
					(troop_get_slot,':itm_qty_supplied','trp_temp_array_a',':array_index'),
					(gt,':itm_qty_demanded',0),
					(gt,':itm_qty_supplied',0),
					(store_add,':item_no',':array_index',trade_goods_begin),
					(str_store_item_name,s12,':item_no'),
					(str_store_string,s11,'@{s11}{s12}, '),
				(try_end),
				(str_store_string,s10,'@I have brought the following items: {s11}.'),
				(assign,':dialog_valid',true),
			(else_try),
				(eq,"$g_kokujin_quest_check","qst_kokujin_defeat_bandits"),
				(check_quest_succeeded,'qst_kokujin_defeat_bandits'),
				(str_store_string,s10,'@I have dealt with those ruffians.'),
				(assign,':dialog_valid',true),
			(try_end),
			(eq,':dialog_valid',true),
			],
     '{s10}',"admin_quest_reward",[]],
    [anyone,"admin_quest_reward",[],"Good work, {playername}. This will not go unnoticed in the future.","admin_pre_talk",
		[
			(try_begin),
				(eq,"$g_kokujin_quest_check","qst_kokujin_needs_goods"),
				(assign,':xp_reward',0),
				(assign,':money_reward',0),
				(party_get_slot,':storehouse_array','$g_encountered_party',slot_town_storehouse_array),
				(party_get_slot,':demand_array','$g_encountered_party',slot_town_demand_array),
				(try_for_range,':temp_array_index',0,num_trade_goods),
					(store_add,':item_no',':temp_array_index',trade_goods_begin),
					(troop_get_slot,':item_qty','trp_temp_array_a',':temp_array_index'),
					(call_script,'script_array_peek',':demand_array',':temp_array_index'),
					(assign,':item_qty_demanded','$return'),
					(gt,':item_qty_demanded',0),
					(gt,':itm_qty',0),
					(call_script,'script_array_modify_value',':storehouse_array',':temp_array_index',op_add,':item_qty'),
					(store_item_value,':item_value',':item_no'),
					(store_mul,':total_value',':item_value',':item_qty'),
					(val_add,':money_reward',':total_value'),
					(store_div,':total_value',10),
					(val_add,':xp_reward',':total_value'),
					(troop_remove_items,"trp_player",':item_no',':item_qty'),
				(try_end),
				(val_mul,':money_reward',3),
				(val_div,':money_reward',2),
				(troop_add_gold,"trp_player",':money_reward'),
				(add_xp_as_reward,':xp_reward'),
				(call_script,'script_modify_town_fame','$g_encountered_party',3),
				(call_script,"script_modify_fame",1),
			(else_try),
				(eq,"$g_kokujin_quest_check","qst_kokujin_defeat_bandits"),
				(troop_add_gold,"trp_player",1440),
				(add_xp_as_reward,750),
				(call_script,'script_modify_town_fame','$g_encountered_party',5),
				(call_script,"script_modify_fame",3),
			(try_end),
			# (call_script,'script_succeed_quest',"$g_kokujin_quest_check"),
			(call_script,'script_end_quest','$g_kokujin_quest_check'),
			(troop_set_slot,'$g_conversation_troop',slot_troop_quest,null),
			(call_script,"script_reset_quest_registers","$g_kokujin_quest_check"),
			]],
    [anyone|plyr,"admin_check_quest_2",[],"I'm not finished yet.","admin_quest_continue",[]],
    [anyone,"admin_quest_continue",[],"Well, get to it. Time waits for no man.","admin_pre_talk",[]],
    [anyone|plyr,"admin_check_quest_2",[],"I can't finish it.","admin_quest_abort",[]],
    [anyone,"admin_quest_abort",[(troop_set_slot,'$g_conversation_troop',slot_troop_quest,null),
								 (call_script,'script_fail_quest','$g_kokujin_quest_check'),
								 #(call_script,"script_end_quest","$g_kokujin_quest_check"),
                                 (call_script,"script_modify_fame",-5)],
     "That is unfortunate. I had high hopes for you.","admin_pre_talk",[]],
	[anyone|plyr,'admin_talk_1',
		[
			(party_get_num_prisoners,':num_prisoners','p_main_party'),
			(gt,':num_prisoners',0),
			],
		"I'd like to collect the bounty on these prisoners.",'admin_bounty',[]],
	[anyone,'admin_bounty',[],'By all means. Anything to rid the countyside of these vermin.','admin_pre_talk',
		[
			(change_screen_trade_prisoners),
			]],
    [anyone|plyr,"admin_talk_1",
		[
			(troop_slot_eq,'$g_conversation_troop',slot_troop_quest_active,false),
			],
     "Do you have any jobs?","admin_give_quest",[]],
    [anyone,"admin_give_quest",[],"Here is a list of what needs doing...","admin_list_quests",[]],
    [anyone|plyr|repeat_for_troops,"admin_list_quests",
		[
			(store_repeat_object,':quest_no'),
			(is_between,':quest_no','qst_kokujin_deliver_msg','qst_jb_faction_scout'),
			(neg|check_quest_active,':quest_no'),
			(try_begin),
				(eq,':quest_no','qst_kokujin_deliver_msg'),
				(str_store_string,s10,'@Deliver a message'),
			(else_try),
				(eq,':quest_no','qst_kokujin_needs_goods'),
				(str_store_string,s10,'@Bring back some goods'),
			(else_try),
				(eq,':quest_no','qst_kokujin_defeat_bandits'),
				(str_store_string,s10,'@Defeat some local hoodlums'),
			(try_end),
			],
		"{s10}","admin_pick_quest",
		[
			(store_repeat_object,':quest_no'),
			(troop_set_slot,'$g_conversation_troop',slot_troop_quest,':quest_no'),
			]],
    [anyone|plyr,"admin_list_quests",[],"Never mind.","admin_quest_deny",[]],
    [anyone|plyr,'admin_pick_quest',
		[
			(troop_get_slot,':quest_no','$g_conversation_troop',slot_troop_quest),
			(try_begin),
				(eq,':quest_no','qst_kokujin_deliver_msg'),
				(str_store_string,s10,"@I'll deliver that message for you"),
			(else_try),
				(eq,':quest_no','qst_kokujin_needs_goods'),
				(str_store_string,s10,"@I'll pick up the those goods you need"),
			(else_try),
				(eq,':quest_no','qst_kokujin_defeat_bandits'),
				(str_store_string,s10,"@I'll take care of your bandit problem."),
			(try_end),
			],
		"{s10}",'admin_quest_assign',[]],
	[anyone,'admin_quest_assign',
		[
			(troop_get_slot,':quest_no','$g_conversation_troop',slot_troop_quest),
			(try_begin),
				(eq,':quest_no',"qst_kokujin_defeat_bandits"),
				(quest_set_slot,':quest_no',slot_quest_giver,'$g_conversation_troop'),
				(str_store_string,s10,'@A group of ruffians is harassing local travelers. Deal with them, and I will reward you handsomely.'),
				(str_store_party_name,s20,'$g_encountered_party'),
				(str_store_troop_name,s12,'$g_conversation_troop'),
				(setup_quest_text,':quest_no'),
				(setup_quest_giver,':quest_no',s12),
			(else_try),
				(eq,':quest_no',"qst_kokujin_needs_goods"),
				(str_clear,s11),
				(party_get_slot,':demand_array','$g_encountered_party',slot_town_demand_array),
				(try_for_range,':array_index',0,num_trade_goods),
					(store_add,':item_no',':array_index',trade_goods_begin),
					(call_script,'script_array_peek',':demand_array',':array_index'),
					(assign,':item_demand_qty','$return'),
					(gt,':item_demand_qty',0),
					(str_store_item_name,s10,':item_no'),
					(str_store_string,s11,'@{s11}{s10}, '),
				(try_end),
				(quest_set_slot,':quest_no',slot_quest_giver,'$g_conversation_troop'),
				(str_store_string,s10,'@Here is a list of the things I need right away: {s11}.'),
				(str_store_party_name,s20,'$g_encountered_party'),
				(str_store_troop_name,s13,'$g_conversation_troop'),
				(setup_quest_text,':quest_no'),
				(setup_quest_giver,':quest_no',s13),
			(else_try),
				(eq,':quest_no',"qst_kokujin_deliver_msg"),
				(assign,':loop_end',false),
				(try_for_range,':unused',0,100),
					(neq,':loop_end',true),
					(call_script,'script_get_random_city'),
					(try_begin),
						(eq,reg0,'$g_encountered_party'),
						(call_script,'script_get_random_city'),
					(else_try),
						(assign,':loop_end',true),
					(try_end),
				(try_end),
				(assign,':msg_dest_party',reg0),
				(party_get_slot,':msg_recipient',':msg_dest_party',slot_town_kokujin),
				(quest_set_slot,':quest_no',slot_quest_target_troop,':msg_recipient'),
				(quest_set_slot,':quest_no',slot_quest_source_party,'$g_encountered_party'),
				(quest_set_slot,':quest_no',slot_quest_target_party,':msg_dest_party'),
				(quest_set_slot,':quest_no',slot_quest_giver,'$g_conversation_troop'),
				(str_store_party_name,s21,':msg_dest_party'),
				(str_store_string,s10,'@I need you to deliver a message to the kokujin of {s21} as soon as possible.'),
				(str_store_party_name,s20,'$g_encountered_party'),
				(str_store_troop_name,s13,'$g_conversation_troop'),
				(setup_quest_text,':quest_no'),
				(setup_quest_giver,':quest_no',s13),
			(try_end),
			(troop_set_slot,'$g_conversation_troop',slot_troop_quest_active,true),
			],
		'{s10}','close_window',
		[
			(troop_get_slot,':quest_no','$g_conversation_troop',slot_troop_quest),
			(try_begin),
				(eq,':quest_no','qst_kokujin_defeat_bandits'),
				(set_spawn_radius,10),
				(spawn_around_party,'$g_encountered_party','pt_bandit_raiders_a'),
				(assign,':bandit_party',reg0),
				(party_set_slot,':bandit_party',slot_party_type,spt_patrol),
				(party_set_slot,':bandit_party',slot_party_ai_state,spai_patrolling_around_center),
				(party_set_slot,':bandit_party',slot_party_ai_object,'$g_encountered_party'),
				(party_set_ai_behavior,':bandit_party',ai_bhvr_patrol_party),
				(party_set_ai_object,':bandit_party','$g_encountered_party'),
				(party_set_ai_patrol_radius,':bandit_party',10),
				(party_set_slot,':bandit_party',slot_spawn_att_to_player,att_hostile),
				(quest_set_slot,':quest_no',slot_quest_target_party,':bandit_party'),
			(try_end),
			(call_script,'script_start_quest',':quest_no'),
			]],
    [anyone,'admin_quest_deny',[],'Well, you did ask. Suit yourself.','admin_pre_talk',[]],
    [anyone|plyr,"admin_talk_1",
		[
			(check_quest_active,'qst_kokujin_deliver_msg'),
            (quest_slot_eq,'qst_kokujin_deliver_msg',slot_quest_target_troop,'$g_conversation_troop'),
			],
     "I was asked to give a message to you.","admin_msg_reward",[]],
    [anyone,"admin_msg_reward",[],"Ah, arigatou! And here is something for you.","admin_pre_talk",
		[
			(quest_get_slot,reg5,'qst_kokujin_deliver_msg',slot_quest_source_party),
			(quest_get_slot,reg6,'qst_kokujin_deliver_msg',slot_quest_target_party),
			(store_distance_to_party_from_party,':quest_reward',reg5,reg6),
			(val_mul,':quest_reward',10),
			(troop_add_gold,"trp_player",':quest_reward'),
			(add_xp_as_reward,150),
			(call_script,"script_modify_fame",1),
			(call_script,'script_succeed_quest','qst_kokujin_deliver_msg'),
			(call_script,'script_end_quest','qst_kokujin_deliver_msg'),
			]],
    [anyone|plyr,"admin_talk_1",[(check_quest_active,'qst_class_merchant')],
     "I'd like to set up my stall.","merchant_stall",[]],
    [anyone|plyr,"admin_talk_1",[],"Nothing, thanks.","close_window",[]],
    [anyone,"current_date",[(try_begin),
                            (eq,"$g_month",1),(str_store_string,1,"str_first_month"),(else_try),
                            (eq,"$g_month",2),(str_store_string,1,"str_second_month"),(else_try),
                            (eq,"$g_month",3),(str_store_string,1,"str_third_month"),(else_try),
                            (eq,"$g_month",4),(str_store_string,1,"str_fourth_month"),(else_try),
                            (eq,"$g_month",5),(str_store_string,1,"str_fifth_month"),(else_try),
                            (eq,"$g_month",6),(str_store_string,1,"str_sixth_month"),(else_try),
                            (eq,"$g_month",7),(str_store_string,1,"str_seventh_month"),(else_try),
                            (eq,"$g_month",8),(str_store_string,1,"str_eighth_month"),(else_try),
                            (eq,"$g_month",9),(str_store_string,1,"str_ninth_month"),(else_try),
                            (eq,"$g_month",10),(str_store_string,1,"str_tenth_month"),(else_try),
                            (eq,"$g_month",11),(str_store_string,1,"str_eleventh_month"),(else_try),
                            (eq,"$g_month",12),(str_store_string,1,"str_twelfth_month"),(try_end),
                            (assign,reg1,"$day"),(assign,reg2,"$year")],
     "It is day {reg1} of the {s1} in the Imperial Year {reg2}.","current_date_2",[]],
    [anyone,"current_date_2",[(eq,"$summer_harvest_active",1)],"The summer crops are being harvested.","fame_level",[]],
    [anyone,"current_date_2",[(eq,"$autumn_harvest_active",1)],"The autumn crops are being harvested.","fame_level",[]],
    [anyone,"current_date_2",[(eq,"$spring_harvest_active",1)],"The spring crops are being harvested.","fame_level",[]],
    [anyone,"current_date_2",[],"There is no harvest right now.","fame_level",[]],
    [anyone,"fame_level",[(troop_get_slot,reg1,"trp_player",slot_player_renown),
                          (try_begin),
                            (lt,reg1,10),(str_store_string,1,"str_fame_lvl0"),
                          (else_try),
                            (is_between,reg1,10,44),(str_store_string,1,"str_fame_lvl1"),
                          (else_try),
                            (is_between,reg1,44,102),(str_store_string,1,"str_fame_lvl2"),
                          (else_try),
                            (ge,reg1,102),(lt,reg1,186),(str_store_string,1,"str_fame_lvl3"),
                          (else_try),
                            (ge,reg1,186),(lt,reg1,296),(str_store_string,1,"str_fame_lvl4"),
                          (else_try),
                            (ge,reg1,296),(lt,reg1,433),(str_store_string,1,"str_fame_lvl5"),
                          (else_try),
                            (ge,reg1,433),(lt,reg1,597),(str_store_string,1,"str_fame_lvl6"),
                          (else_try),
                            (ge,reg1,597),(lt,reg1,788),(str_store_string,1,"str_fame_lvl7"),
                          (else_try),
                            (ge,reg1,788),(lt,reg1,1006),(str_store_string,1,"str_fame_lvl8"),
                          (else_try),
                            (ge,reg1,1006),(str_store_string,1,"str_fame_lvl9"),
                          (try_end)],
     "{s1}","admin_pre_talk",[]],
    [anyone,"merchant_stall",
		[
			(neg|is_currently_night),
			(store_skill_level,reg1,skl_trade,"trp_player"),
			(val_mul,reg1,reg1),
			],
     "Sure. The fee is {reg1} mon.","merchant_stall_2",[]],
    [anyone,"merchant_stall",
		[
			(is_currently_night),
			],
     "Sorry, but it is too late.","admin_pre_talk",[]],
    [anyone|plyr,"merchant_stall_2",[(store_skill_level,':trade_skill',skl_trade,"trp_player"),
                                     (val_mul,':trade_skill',':trade_skill'),
                                     (store_troop_gold,':available_cash',"trp_player"),
                                     (ge,':available_cash',':trade_skill'),
									 (assign,reg1,':trade_skill')],
     "{reg1} mon it is.","merchant_stall_3",[(troop_remove_gold,"trp_player",reg1)]],
    [anyone|plyr,"merchant_stall_2",[(store_skill_level,reg1,skl_trade,"trp_player")],
     "I don't have {reg1} mon.","merchant_stall_4",[]],
    [anyone,"merchant_stall_3",[(jump_to_menu,"mnu_merchant")],"Thank you. Good luck.","close_window",[]],
    [anyone,"merchant_stall_4",[(store_skill_level,reg1,skl_trade,"trp_player")],
     "A merchant without {reg1} mon? How sad. ","close_window",[]],

    
    [trp_kuge,"start",
		[	
			(assign,':dialog_valid',false),
			(try_begin),
				(call_script,'script_cf_object_flag_set',obj_quest,'qst_kuge_entertain_visiting_kuge',slot_quest_flags,3),
				(assign,':dialog_valid',true),
			(else_try),
				(call_script,'script_cf_object_flag_set',obj_quest,'qst_kuge_entertain_visiting_kuge',slot_quest_flags,2),
				(assign,':dialog_valid',true),
			(else_try),
				(call_script,'script_cf_object_flag_set',obj_quest,'qst_kuge_entertain_visiting_kuge',slot_quest_flags,1),
				(assign,':dialog_valid',true),
			(try_end),
			(eq,':dialog_valid',true),
			],
	"I must be going now. Good day.","close_window",[]],
    [trp_kuge,"start",
		[
			(check_quest_active,"qst_kuge_entertain_visiting_kuge"),
			(assign,':dialog_valid',true),
			(try_begin),
				(call_script,'script_cf_object_flag_set',obj_quest,'qst_kuge_entertain_visiting_kuge',slot_quest_flags,3),
				(assign,':dialog_valid',false),
			(else_try),
				(call_script,'script_cf_object_flag_set',obj_quest,'qst_kuge_entertain_visiting_kuge',slot_quest_flags,2),
				(assign,':dialog_valid',false),
			(else_try),
				(call_script,'script_cf_object_flag_set',obj_quest,'qst_kuge_entertain_visiting_kuge',slot_quest_flags,1),
				(assign,':dialog_valid',false),
			(try_end),
			(eq,':dialog_valid',true),
			(quest_get_slot,':quest_item','qst_kuge_entertain_visiting_kuge',slot_quest_item_1),
			(troop_remove_item,"trp_player",':quest_item'),
			(try_begin),
				(eq,"$kuge_type",1),
				(try_begin),
					(eq,':quest_item',"itm_sesshu_painting"),
					(str_store_string,10,"str_kuge_gift_2"),
					(call_script,'script_object_set_flag',obj_quest,'qst_kuge_entertain_visiting_kuge',slot_quest_flags,2,1),
				(else_try),
					(eq,':quest_item',"itm_genji_monogatari"),
					(str_store_string,10,"str_kuge_gift_3"),
					(call_script,'script_object_set_flag',obj_quest,'qst_kuge_entertain_visiting_kuge',slot_quest_flags,1,1),
				(else_try),
					(eq,':quest_item',"itm_elaborate_pottery"),
					(str_store_string,10,"str_kuge_gift_2"),
					(call_script,'script_object_set_flag',obj_quest,'qst_kuge_entertain_visiting_kuge',slot_quest_flags,2,1),
				(else_try),
					(eq,':quest_item',"itm_calligraphy_scrolls"),
					(str_store_string,10,"str_kuge_gift_2"),
					(call_script,'script_object_set_flag',obj_quest,'qst_kuge_entertain_visiting_kuge',slot_quest_flags,2,1),
				(else_try),
					(eq,':quest_item',"itm_chinese_silk"),
					(str_store_string,10,"str_kuge_gift_1"),
					(call_script,'script_object_set_flag',obj_quest,'qst_kuge_entertain_visiting_kuge',slot_quest_flags,3,1),
				(try_end),
			(else_try),
				(eq,"$kuge_type",2),
				(try_begin),
					(eq,':quest_item',"itm_sesshu_painting"),
					(str_store_string,10,"str_kuge_gift_2"),
					(call_script,'script_object_set_flag',obj_quest,'qst_kuge_entertain_visiting_kuge',slot_quest_flags,2,1),
				(else_try),
					(eq,':quest_item',"itm_genji_monogatari"),
					(str_store_string,10,"str_kuge_gift_2"),
					(call_script,'script_object_set_flag',obj_quest,'qst_kuge_entertain_visiting_kuge',slot_quest_flags,2,1),
				(else_try),
					(eq,':quest_item',"itm_elaborate_pottery"),
					(str_store_string,10,"str_kuge_gift_2"),
					(call_script,'script_object_set_flag',obj_quest,'qst_kuge_entertain_visiting_kuge',slot_quest_flags,2,1),
				(else_try),
					(eq,':quest_item',"itm_calligraphy_scrolls"),
					(str_store_string,10,"str_kuge_gift_1"),
					(call_script,'script_object_set_flag',obj_quest,'qst_kuge_entertain_visiting_kuge',slot_quest_flags,3,1),
				(else_try),
					(eq,':quest_item',"itm_chinese_silk"),
					(str_store_string,10,"str_kuge_gift_3"),
					(call_script,'script_object_set_flag',obj_quest,'qst_kuge_entertain_visiting_kuge',slot_quest_flags,1,1),
				(try_end),
			(else_try),
				(eq,"$kuge_type",3),
				(try_begin),
					(eq,':quest_item',"itm_sesshu_painting"),
					(str_store_string,10,"str_kuge_gift_2"),
					(call_script,'script_object_set_flag',obj_quest,'qst_kuge_entertain_visiting_kuge',slot_quest_flags,2,1),
				(else_try),
					(eq,':quest_item',"itm_genji_monogatari"),
					(str_store_string,10,"str_kuge_gift_1"),
					(call_script,'script_object_set_flag',obj_quest,'qst_kuge_entertain_visiting_kuge',slot_quest_flags,3,1),
				(else_try),
					(eq,':quest_item',"itm_elaborate_pottery"),
					(str_store_string,10,"str_kuge_gift_2"),
					(call_script,'script_object_set_flag',obj_quest,'qst_kuge_entertain_visiting_kuge',slot_quest_flags,2,1),
				(else_try),
					(eq,':quest_item',"itm_calligraphy_scrolls"),
					(str_store_string,10,"str_kuge_gift_3"),
					(call_script,'script_object_set_flag',obj_quest,'qst_kuge_entertain_visiting_kuge',slot_quest_flags,1,1),
				(else_try),
					(eq,':quest_item',"itm_chinese_silk"),
					(str_store_string,10,"str_kuge_gift_2"),
					(call_script,'script_object_set_flag',obj_quest,'qst_kuge_entertain_visiting_kuge',slot_quest_flags,2,1),
				(try_end),
			(else_try),
				(eq,"$kuge_type",4),
				(try_begin),
					(eq,':quest_item',"itm_sesshu_painting"),
					(str_store_string,10,"str_kuge_gift_1"),
					(call_script,'script_object_set_flag',obj_quest,'qst_kuge_entertain_visiting_kuge',slot_quest_flags,3,1),
				(else_try),
					(eq,':quest_item',"itm_genji_monogatari"),
					(str_store_string,10,"str_kuge_gift_2"),
					(call_script,'script_object_set_flag',obj_quest,'qst_kuge_entertain_visiting_kuge',slot_quest_flags,2,1),
				(else_try),
					(eq,':quest_item',"itm_elaborate_pottery"),
					(str_store_string,10,"str_kuge_gift_3"),
					(call_script,'script_object_set_flag',obj_quest,'qst_kuge_entertain_visiting_kuge',slot_quest_flags,1,1),
				(else_try),
					(eq,':quest_item',"itm_calligraphy_scrolls"),
					(str_store_string,10,"str_kuge_gift_2"),
					(call_script,'script_object_set_flag',obj_quest,'qst_kuge_entertain_visiting_kuge',slot_quest_flags,2,1),
				(else_try),
					(eq,':quest_item',"itm_chinese_silk"),
					(str_store_string,10,"str_kuge_gift_2"),
					(call_script,'script_object_set_flag',obj_quest,'qst_kuge_entertain_visiting_kuge',slot_quest_flags,2,1),
				(try_end),
			(else_try),
				(eq,"$kuge_type",5),
				(try_begin),
					(eq,':quest_item',"itm_sesshu_painting"),
					(str_store_string,10,"str_kuge_gift_3"),
					(call_script,'script_object_set_flag',obj_quest,'qst_kuge_entertain_visiting_kuge',slot_quest_flags,1,1),
				(else_try),
					(eq,':quest_item',"itm_genji_monogatari"),
					(str_store_string,10,"str_kuge_gift_2"),
					(call_script,'script_object_set_flag',obj_quest,'qst_kuge_entertain_visiting_kuge',slot_quest_flags,2,1),
				(else_try),
					(eq,':quest_item',"itm_elaborate_pottery"),
					(str_store_string,10,"str_kuge_gift_1"),
					(call_script,'script_object_set_flag',obj_quest,'qst_kuge_entertain_visiting_kuge',slot_quest_flags,3,1),
				(else_try),
					(eq,':quest_item',"itm_calligraphy_scrolls"),
					(str_store_string,10,"str_kuge_gift_2"),
					(call_script,'script_object_set_flag',obj_quest,'qst_kuge_entertain_visiting_kuge',slot_quest_flags,2,1),
				(else_try),
					(eq,':quest_item',"itm_chinese_silk"),
					(str_store_string,10,"str_kuge_gift_2"),
					(call_script,'script_object_set_flag',obj_quest,'qst_kuge_entertain_visiting_kuge',slot_quest_flags,2,1),
				(try_end),
			(try_end),
			],
		"{s10}","visiting_kuge",[]],
    
#Hosokawa shugo introduction dialogs
    [anyone,"start",
		[
			(store_conversation_troop,':conversation_partner'),
			(this_or_next|check_quest_active,'qst_class_bushi'),
			(check_quest_active,'qst_class_kuge'),
			(is_between,':conversation_partner',hosokawa_shugo_begin,yamana_shugo_end),
			(try_begin),
				(check_quest_active,"qst_kuge_war_materials"),
				(assign,':qst_bushi_war_materials','qst_kuge_war_materials'),
			(else_try),
				(check_quest_active,"qst_bushi_war_materials"),
				(assign,':qst_bushi_war_materials','qst_bushi_war_materials'),
			(try_end),
			(check_quest_active,':qst_bushi_war_materials'),
			(quest_slot_eq,":qst_bushi_war_materials",slot_quest_target_troop,':conversation_partner'),
			(quest_get_slot,':quest_item',':qst_bushi_war_materials',slot_quest_item_1),
			(troop_remove_item,"trp_player",":quest_item"),
			(str_store_item_name,s10,":quest_item"),
			(add_xp_as_reward,1500),
			(troop_add_gold,"trp_player",1000),
			(call_script,'script_end_quest',':qst_bushi_war_materials'),
			],
     "I thank you for the shipment of {s10}. The fighting has been fierce of late. I hope your reward is sufficient.","close_window",[]],
	[anyone|repeat_for_troops,'start',
		[
			(store_repeat_object,':quest_no'),
			(is_between,':quest_no','qst_jb_faction_scout','qst_ronin_storyline_capture_bandit_leader'),
			(store_conversation_troop,'$g_conversation_troop'),
			(is_between,'$g_conversation_troop',hosokawa_shugo_begin,yamana_shugo_end),
			(check_quest_active,':quest_no'),
			(store_troop_faction,':conversation_troop_faction','$g_conversation_troop'),
			(try_begin),
				(call_script,'script_cf_faction_is_ally_of_faction','fac_hosokawa',':conversation_troop_faction'),
				(assign,':target_faction','fac_hosokawa'),
			(else_try),
				(assign,':target_faction','fac_yamana'),
			(try_end),
			(assign,':selection_valid',false),
			(try_begin),
				(eq,':quest_no','qst_jb_faction_deliver_msg'),
				(quest_slot_eq,'qst_jb_faction_deliver_msg',slot_quest_target_troop,'$g_conversation_troop'),
				(assign,':selection_valid',true),
				(str_store_string,s10,'@My thanks for your delivery. I hope you find your reward sufficient.'),
			(else_try),
				(eq,':quest_no','qst_jb_faction_scout'),
				(quest_slot_eq,'qst_jb_faction_deliver_msg',slot_quest_giver,'$g_conversation_troop'),
				(check_quest_succeeded,'qst_jb_faction_scout'),
				(assign,':selection_valid',true),
				(str_store_string,s10,'@You have done well; my men have been dispatched. I hope you find your reward sufficient.'),
			(else_try),
				(eq,':quest_no','qst_jb_faction_deliver_koban'),
				(quest_slot_eq,'qst_jb_faction_deliver_msg',slot_quest_target_troop,'$g_conversation_troop'),
				(quest_get_slot,':quest_itm_count','qst_jb_faction_deliver_koban',slot_quest_item_1_cnt),
				(call_script,'script_troop_get_item_count','trp_player','itm_koban'),
				(eq,reg0,':quest_itm_count'),
				(troop_remove_items,'trp_player','itm_koban',':quest_itm_count'),
				(assign,':selection_valid',true),
				(str_store_string,s10,'@Our trust in you was well placed. I hope you find your reward sufficient.'),
			(else_try),
				(eq,':quest_no','qst_jb_faction_escort_noble'),
				(quest_slot_eq,'qst_jb_faction_deliver_msg',slot_quest_giver,'$g_conversation_troop'),
				(check_quest_succeeded,'qst_jb_faction_escort_noble'),
				(assign,':selection_valid',true),
				(str_store_faction_name,s11,':target_faction'),
				(str_store_string,s10,'@You have the gratitude of the {s11}. I hope you find your reward sufficient.'),
			(try_end),
			(eq,':selection_valid',true),
			],
		'{s10}','jb_msg_end',
		[
			(store_repeat_object,':quest_no'),
			(try_begin),
				(eq,':quest_no','qst_jb_faction_deliver_msg'),
				(troop_add_items,'trp_player','itm_string_of_coins',5),
				(add_xp_as_reward,250),
			(else_try),
				(eq,':quest_no','qst_jb_faction_scout'),
				(troop_add_items,'trp_player','itm_string_of_coins',15),
				(add_xp_as_reward,500),
			(else_try),
				(eq,':quest_no','qst_jb_faction_deliver_koban'),
				(troop_add_items,'trp_player','itm_koban',5),
				(add_xp_as_reward,1000),
			(else_try),
				(eq,':quest_no','qst_jb_faction_escort_noble'),
				(troop_add_items,'trp_player','itm_stack_of_koban',1),
				(add_xp_as_reward,2000),
			(try_end),
			(call_script,'script_end_quest',':quest_no'),
			]],
	[anyone|plyr,'jb_msg_end',[],'Most sufficient. Good day to you.','close_window',[]],
    [anyone,"start",
		[
			(check_quest_active,"qst_kuge_entertain_visiting_kuge"),
			(store_current_scene,':cur_scene'),
			(eq,':cur_scene',"scn_inn"),
			(store_conversation_troop,':local_conversation_troop'),
			(eq,':local_conversation_troop','$g_conversation_troop'),
			(quest_slot_eq,'qst_kuge_entertain_visiting_kuge',slot_quest_flags,0),
			],
	"I must know what our guest thinks of his gift. Please go speak with him.","close_window",[]],
    [anyone,"visiting_kuge",
		[
			(assign,':dialog_valid',false),
			(try_begin),
				(call_script,'script_cf_object_flag_set',obj_quest,'qst_kuge_entertain_visiting_kuge',slot_quest_flags,3),
				(str_store_string,s12,'@.'),
				(assign,':dialog_valid',true),
			(else_try),
				(call_script,'script_cf_object_flag_set',obj_quest,'qst_kuge_entertain_visiting_kuge',slot_quest_flags,2),
				(store_attribute_level,':player_chr',"trp_player",ca_charisma),
				(ge,':player_chr',12),
				(str_store_string,s12,'@, thanks to you.'),
				(assign,':dialog_valid',true),
			(else_try),
				(call_script,'script_cf_object_flag_set',obj_quest,'qst_kuge_entertain_visiting_kuge',slot_quest_flags,1),
				(store_attribute_level,':player_chr',"trp_player",ca_charisma),
				(ge,':player_chr',18),
				(str_store_string,s12,'@, thanks to you.'),
				(assign,':dialog_valid',true),
			(try_end),
			(eq,':dialog_valid',true),
			(call_script,'script_object_set_flag',obj_quest,'qst_kuge_entertain_visiting_kuge',slot_quest_flags,3,1),
			],
	"This has been a surprisingly pleasant journey{s12} I should make a point to return again.","close_window",[]],
    [anyone,"visiting_kuge",
		[
			(assign,':dialog_valid',false),
			(try_begin),
				(call_script,'script_cf_object_flag_set',obj_quest,'qst_kuge_entertain_visiting_kuge',slot_quest_flags,2),
				(assign,':dialog_valid',true),
			(else_try),
				(call_script,'script_cf_object_flag_set',obj_quest,'qst_kuge_entertain_visiting_kuge',slot_quest_flags,1),
				(store_attribute_level,':player_chr',"trp_player",ca_charisma),
				(ge,':player_chr',15),
			(try_end),
			(eq,':dialog_valid',true),
			(call_script,'script_object_set_flag',obj_quest,'qst_kuge_entertain_visiting_kuge',slot_quest_flags,2,1),
			],
		"This place is pretty boring actually, but at least it was funny watching the shugo fall over himself to please me.","close_window",[]],
    [anyone,"visiting_kuge",
		[
			(call_script,'script_cf_object_flag_set',obj_quest,'qst_kuge_entertain_visiting_kuge',slot_quest_flags,1),
			],
		"Ugh! I can't understand why I even considered leaving the court. This place is just uncivilized.","close_window",[]],
    [anyone,"start",
		[
			(store_conversation_troop,'$g_conversation_troop'),
			(is_between,'$g_conversation_troop',hosokawa_shugo_begin,hosokawa_shugo_end),
			],
     "Greetings...","shugo_start_0",[]],
	[anyone|plyr,'shugo_start_0',[],"I believe some of my troops belong to you.",'shugo_start_troop_transfer',[]],
	[anyone|plyr,'shugo_start_0',
		[
			(neg|check_quest_active,'qst_class_bushi'),
			(neg|check_quest_active,'qst_class_kuge'),
			],
		'Do you have any jobs that need doing?','shugo_job_board',[]],
	[anyone|plyr,'shugo_start_0',[],'I must speak with you.','shugo_start_1',[]],
	[anyone,'shugo_start_troop_transfer',[],'Indeed. Which troop do you wish to transfer?','shugo_troop_transfer_choose',[]],
	[anyone|plyr|repeat_for_troops,'shugo_troop_transfer_choose',
		[
			(store_repeat_object,'$g_target_troop'),
			(party_count_companions_of_type,':target_troop_count','p_main_party','$g_target_troop'),
			(gt,':target_troop_count',0),
			(store_troop_faction,':conversation_troop_faction','$g_conversation_troop'),
			(store_troop_faction,':target_troop_faction','$g_target_troop'),
			(call_script,'script_cf_faction_is_ally_of_faction',':target_troop_faction',':conversation_troop_faction'),
			(store_relation,':player_relation_with_faction','fac_player_faction',':conversation_troop_faction'),
			(lt,':player_relation_with_faction',0),
			(str_store_troop_name,s11,'$g_target_troop'),
			(str_store_faction_name,s12,':conversation_troop_faction'),
			],
		'{s12} {s11}','shugo_transfer_troops',
		[
			(store_repeat_object,'$g_target_troop'),
			]],
	[anyone|plyr,'shugo_troop_transfer_choose',[],'Never mind','shugo_transfer_end',[]],
	[anyone,'shugo_transfer_end',[],'I do not have time for this. Be gone!','close_window',[]],
	[anyone,'shugo_transfer_troops',
		[
			(store_troop_faction,':troop_faction','$g_target_troop'),
			(call_script,'script_troop_transfer','$g_target_troop',':troop_faction'),
			],
	"Very well, {playername}. The transfer is complete. Now go, before I change my mind.",'close_window',[]],
	[anyone,'shugo_job_board',[],'Normally I would have one of my retainers do this, but there are a few things I need done...','shugo_list_jobs',[]],
	[anyone|plyr|repeat_for_troops,'shugo_list_jobs',
		[
			(store_repeat_object,':quest_no'),
			# (is_between,':quest_no','qst_jb_faction_scout','qst_ronin_storyline_capture_bandit_leader'),
			(is_between,':quest_no','qst_jb_faction_scout','qst_jb_faction_escort_noble'),
			(neg|check_quest_active,':quest_no'),
			(assign,':selection_valid',false),
			(store_troop_faction,':conversation_troop_faction','$g_conversation_troop'),
			(try_begin),
				(call_script,'script_cf_faction_is_ally_of_faction','fac_hosokawa',':conversation_troop_faction'),
				(assign,':target_faction','fac_hosokawa'),
			(else_try),
				(assign,':target_faction','fac_yamana'),
			(try_end),
			(store_relation,':relation','fac_player_faction',':target_faction'),
			(try_begin),
				(eq,':quest_no','qst_jb_faction_deliver_msg'),
				(gt,':relation',-5),
				(assign,':selection_valid',true),
				(str_store_string,s10,'@Deliver a message'),
			(else_try),
				(eq,':quest_no','qst_jb_faction_scout'),
				(gt,':relation',5),
				(assign,':selection_valid',true),
				(str_store_string,s10,'@Scout for the shugo'),
			(else_try),
				(eq,':quest_no','qst_jb_faction_deliver_koban'),
				(gt,':relation',15),
				(troop_get_inventory_capacity,':inv_cap','trp_player'),
				(ge,':inv_cap',5),
				(assign,':selection_valid',true),
				(str_store_string,s10,'@Deliver a shipment of koban'),
			(else_try),
				(eq,':quest_no','qst_jb_faction_escort_noble'),
				(gt,':relation',25),
				(assign,':selection_valid',true),
				(str_store_string,s10,'@Escort a noble'),
			(try_end),
			(eq,':selection_valid',true),
			],
		'{s10}','shugo_select_job',
		[
			(store_repeat_object,':quest_no'),
			(call_script,'script_object_modify_slot',obj_troop,'$g_conversation_troop',slot_troop_quest,op_asn,':quest_no'),
			]],
	[anyone|plyr,'shugo_list_jobs',[],'Never mind','shugo_cancel_job_board',[]],
	[anyone|plyr,'shugo_select_job',
		[
			(troop_get_slot,':quest_no','$g_conversation_troop',slot_troop_quest),
			(str_clear,s10),
			(try_begin),
				(eq,':quest_no','qst_jb_faction_deliver_msg'),
				(str_store_string,s10,"@I'll deliver that message you mentioned"),
			(else_try),
				(eq,':quest_no','qst_jb_faction_scout'),
				(str_store_string,s10,"@I'll scout for you"),
			(else_try),
				(eq,':quest_no','qst_jb_faction_deliver_koban'),
				(str_store_string,s10,"@A shipment of koban sounds interesting"),
			(else_try),
				(eq,':quest_no','qst_jb_faction_escort_noble'),
				(str_store_string,s10,"@I will escort the noble"),
			(try_end),
			],
		'{s10}','shugo_assign_job',[]],
	[anyone,'shugo_assign_job',
		[
			(troop_get_slot,':quest_no','$g_conversation_troop',slot_troop_quest),
			(str_clear,s10),
			(store_troop_faction,':conversation_troop_faction','$g_conversation_troop'),
			(try_begin),
				(call_script,'script_cf_faction_is_ally_of_faction','fac_hosokawa',':conversation_troop_faction'),
				(assign,':target_faction','fac_hosokawa'),
			(else_try),
				(assign,':target_faction','fac_yamana'),
			(try_end),
			(try_begin),
				(eq,':quest_no','qst_jb_faction_deliver_msg'),
				(try_begin),
					(eq,':target_faction','fac_hosokawa'),
					(store_random_in_range,':target_troop','trp_takase_shugo','trp_hidaka_shugo'),
				(else_try),
					(store_random_in_range,':target_troop','trp_hidaka_shugo','trp_bushi_1'),
				(try_end),
				(try_for_range,':town',cities_begin,towns_end),
					(party_get_slot,':shugo',':town',slot_town_shugo),
					(eq,':shugo',':target_troop'),
					(assign,':target_party',':town'),
				(try_end),
				(quest_set_slot,':quest_no',slot_quest_giver,'$g_conversation_troop'),
				(quest_set_slot,':quest_no',slot_quest_target_troop,':target_troop'),
				(quest_set_slot,':quest_no',slot_quest_target_party,':target_party'),
				(str_store_party_name,s11,'$g_encountered_party'),
				(str_store_party_name,s12,':target_party'),
				(setup_quest_text,'qst_jb_faction_deliver_msg'),
				(str_store_troop_name,s14,'$g_conversation_troop'),
				(setup_quest_giver,'qst_jb_faction_deliver_msg',s14),
				(str_store_troop_name,s13,':target_troop'),
				(str_store_string,s10,"@Very well. Give this message to {s13} as soon as possible."),
			(else_try),
				(eq,':quest_no','qst_jb_faction_scout'),
				(try_begin),
					(eq,':target_faction','fac_hosokawa'),
					(quest_set_slot,':quest_no',slot_quest_target_party_template,'pt_yamana_patrol'),
				(else_try),
					(quest_set_slot,':quest_no',slot_quest_target_party_template,'pt_hosokawa_patrol'),
				(try_end),
				(quest_set_slot,':quest_no',slot_quest_giver,'$g_conversation_troop'),
				(str_store_faction_name,s12,':conversation_troop_faction'),
				(str_store_troop_name,s11,'$g_conversation_troop'),
				(setup_quest_text,'qst_jb_faction_scout'),
				(setup_quest_giver,'qst_jb_faction_scout',s11),
				(str_store_string,s10,"@Good. Find an enemy patrol and report back to me. My men will take care of the rest"),
			(else_try),
				(eq,':quest_no','qst_jb_faction_deliver_koban'),
				(try_begin),
					(eq,':target_faction','fac_hosokawa'),
					(store_random_in_range,':target_troop','trp_takase_shugo','trp_hidaka_shugo'),
				(else_try),
					(store_random_in_range,':target_troop','trp_hidaka_shugo','trp_bushi_1'),
				(try_end),
				(try_for_range,':town',cities_begin,towns_end),
					(party_get_slot,':shugo',':town',slot_town_shugo),
					(eq,':shugo',':target_troop'),
					(assign,':target_party',':town'),
				(try_end),
				(store_random_in_range,':item_count',2,6),
				(troop_add_items,'trp_player','itm_stack_of_koban',':item_count'),
				(quest_set_slot,':quest_no',slot_quest_giver,'$g_conversation_troop'),
				(quest_set_slot,':quest_no',slot_quest_target_troop,':target_troop'),
				(quest_set_slot,':quest_no',slot_quest_target_party,':target_party'),
				(quest_set_slot,':quest_no',slot_quest_item_1,'itm_stack_of_koban'),
				(quest_set_slot,':quest_no',slot_quest_item_1_cnt,':item_count'),
				(assign,reg10,':item_count'),
				(str_store_party_name,s11,':target_party'),
				(setup_quest_text,':quest_no'),
				(str_store_troop_name,s12,':target_troop'),
				(str_store_troop_name,s13,'$g_conversation_troop'),
				(setup_quest_giver,':quest_no',s13),
				(str_store_string,s10,"@Deliver these {reg10} stacks of koban to {s12} in {s11}. Don't try anything stupid."),
			(else_try),
				(eq,':quest_no','qst_jb_faction_escort_noble'),
				(call_script,'script_select_random_faction_city',':target_faction'),
				(assign,':target_party','$return'),
				(str_store_string,s10,"@You have not failed me before, {playername}. I trust you will escort {s12} safely to {s11}."),
			(try_end),
			],
		'{s10}','close_window',
		[
			(troop_get_slot,':quest_no','$g_conversation_troop',slot_troop_quest),
			(call_script,'script_start_quest',':quest_no'),
			]],
	[anyone,'shugo_cancel_job_board',[],'You waste my time. Leave now.','close_window',[]],
    [anyone|plyr,"shugo_start_1",
		[
			(check_quest_active,'qst_intro_kuge_deliver_msg'),
			(neg|check_quest_succeeded,'qst_intro_kuge_deliver_msg'),
			(store_conversation_troop,reg10),
			(party_slot_eq,'qst_intro_kuge_deliver_msg',slot_quest_target_troop,reg10),
			],
     "I bring a message from Hosokawa katsumoto.","shugo_intro_kuge_quest",[]],
    [anyone,"shugo_intro_kuge_quest",[],"Very good, {playername}. You have served our lord well, and I will inform him of it. Return now for your reward.",
     "close_window",
     [
         (call_script,'script_succeed_quest',"qst_intro_kuge_deliver_msg"),
         (call_script,'script_modify_fame',5),
         (add_xp_as_reward,100),
         ]],
    [anyone,"shugo_start_1",
     [
         (store_relation,reg4,"fac_hosokawa","fac_player_faction"),
         (eq,reg4,0),
         (this_or_next|neg|check_quest_active,'qst_class_bushi'),
         (neg|check_quest_active,'qst_class_kuge'),
         ],
     "I have little time, {playername}. If you wish to join the Hosokawa in our fight against the Yamana, go speak with Hosokawa Katsumoto in Kyoto.",
     "close_window",[(troop_add_items,'trp_player','itm_hosokawa_intro_letter',1)]],
    [anyone,"shugo_start_1",
     [
         (store_relation,reg4,"fac_hosokawa","fac_player_faction"),
         (lt,reg4,0),
         (troop_add_item,'trp_player','itm_hosokawa_intro_letter'),
         ],
     "You have angered the Hosokawa. If you wish to redeem yourself to us, speak with Hosokawa Katsumoto in Kyoto.",
     "close_window",[(troop_add_items,'trp_player','itm_hosokawa_intro_letter',1)]],
    [anyone,"shugo_start_1",
     [
         (store_conversation_troop,reg1),
         (faction_slot_eq,'fac_hosokawa',slot_faction_joined,true),
         (troop_get_slot,reg6,"trp_player",slot_player_lord),
         (troop_get_slot,reg7,"trp_player",slot_player_town),
         (gt,reg6,0),
         (neq,reg6,reg1),
         (str_store_troop_name,1,reg6),
         (str_store_party_name,2,reg7),
         ],
     "{s1} speaks highly of you, {playername}-{dono/hime}. See him in {s2} for your next mission",
     "close_window",[]],
    [anyone,"shugo_start_1",
     [
         (store_conversation_troop,reg1),
         (store_relation,reg4,"fac_hosokawa","fac_player_faction"),
         (gt,reg4,0),
         (this_or_next|check_quest_active,'qst_class_bushi'),
         (check_quest_active,'qst_class_kuge'),
         (faction_slot_neq,'fac_hosokawa',slot_faction_joined,true),
		 ],
     "Go speak with Hosokawa Katsumoto in Kyoto to be assigned to a shugo.",
     "close_window",
	 [
		(troop_add_item,'trp_player','itm_hosokawa_intro_letter'),
		]],
    [anyone,"shugo_start_1",
     [
         (store_conversation_troop,reg1),
         (troop_get_slot,reg6,"trp_player",slot_player_lord),
         (eq,reg6,reg1),
         ],
     "Welcome back, {playername}-{dono/hime}...",
     "shugo_pre_talk",[]],
#Yamana shugo introduction dialogs
    [anyone,"start",
		[
			(store_conversation_troop,'$g_conversation_troop'),
			(is_between,'$g_conversation_troop',yamana_shugo_begin,yamana_shugo_end),
			],
     "Greetings...","yamana_shugo_start_1",[]],
    [anyone|plyr,"yamana_shugo_start_1",
		[
			(check_quest_active,'qst_intro_kuge_deliver_msg'),
			(neg|check_quest_succeeded,'qst_intro_kuge_deliver_msg'),
			(party_slot_eq,'qst_intro_kuge_deliver_msg',slot_quest_target_troop,'$g_conversation_troop'),
			],
     "I bring a message from Yamana Souzen.","shugo_intro_kuge_quest",[]],
    [anyone,"yamana_shugo_start_1",
     [
         (store_relation,reg4,"fac_yamana","fac_player_faction"),
         (eq,reg4,0),
         (this_or_next|neg|check_quest_active,'qst_class_bushi'),
         (neg|check_quest_active,'qst_class_kuge'),
         ],
     "I have little time, {playername}. If you wish to join the Yamana in our fight against the Hosokawa, go speak with Yamana Souzen in Kyoto.",
     "close_window",[(troop_add_items,'trp_player','itm_yamana_intro_letter',1)]],
    [anyone,"yamana_shugo_start_1",
     [
         (store_relation,reg4,"fac_yamana","fac_player_faction"),
         (lt,reg4,0),
         (troop_add_item,'trp_player','itm_yamana_intro_letter'),
         ],
     "You have angered the Yamana. If you wish to redeem yourself to us, speak with Yamana Souzen in Kyoto.",
     "close_window",[(troop_add_items,'trp_player','itm_yamana_intro_letter',1)]],
    [anyone,"yamana_shugo_start_1",
     [
         (faction_slot_eq,'fac_yamana',slot_faction_joined,true),
         (troop_get_slot,':player_lord',"trp_player",slot_player_lord),
         (troop_get_slot,':player_town',"trp_player",slot_player_town),
         (gt,':player_lord',0),
         (neq,':player_lord','$g_conversation_troop'),
         (str_store_troop_name,1,':player_lord'),
         (str_store_party_name,2,':player_town'),
         ],
     "{s1} speaks highly of you, {playername}-{dono/hime}. See him in {s2} for your next mission",
     "close_window",[]],
    [anyone,"yamana_shugo_start_1",
     [
         (store_relation,':relation_with_faction',"fac_yamana","fac_player_faction"),
         (gt,':relation_with_faction',0),
         (this_or_next|check_quest_active,'qst_class_bushi'),
         (check_quest_active,'qst_class_kuge'),
         (faction_slot_eq,'fac_yamana',slot_faction_joined,false),
		 ],
     "Go speak with Yamana Souzen in Kyoto to be assigned to a shugo.",
     "close_window",
	 [
		(troop_add_item,'trp_player','itm_yamana_intro_letter'),
		]],
    [anyone,"yamana_shugo_start_1",
     [
         (faction_slot_eq,'fac_yamana',slot_faction_joined,true),
         (troop_get_slot,':player_lord',"trp_player",slot_player_lord),
         (eq,':player_lord','$g_conversation_troop'),
         ],
     "Welcome back, {playername}-{dono/hime}...",
     "shugo_pre_talk",[]],
#Shugo dialogs
	[anyone,'shugo_pre_talk',
		[
			(troop_get_slot,':rank_array','trp_player',slot_player_rank_array),
			(troop_get_slot,':rank_array_ptr','trp_player',slot_player_rank_ptr),
			(call_script,'script_cf_get_progress_to_next_rank',':rank_array',':rank_array_ptr'),
			],
		'Congratulations, {playername}. You now rank as a {s11}, and your wages are now {reg10} mon per week. Well done.','shugo_pre_talk',
		[
			(troop_get_slot,':rank_array','trp_player',slot_player_rank_array),
			(call_script,'script_object_modify_slot',obj_troop,'trp_player',slot_player_rank_ptr,op_add,1),
			(troop_get_slot,':rank_array_ptr','trp_player',slot_player_rank_ptr),
			(call_script,'script_get_rank_title',':rank_array',':rank_array_ptr'),
			(assign,':title',reg0),
			(call_script,'script_get_rank_pay_and_fp_rate',':rank_array',':rank_array_ptr'),
			(assign,':pay_rate',reg0),
			(str_store_string,s11,':title'),
			(assign,reg10,':pay_rate'),
			]],
    [anyone,"shugo_pre_talk",[],"My time is short, {playername}. What do you want? By the way, you have {reg1} faction points.","shugo_talk_1",
		[
			(troop_get_slot,reg1,"trp_player",slot_player_faction_points),
			]],
    [anyone,"shugo_pre_talk_2",[],"Anything else?","shugo_talk_1",[]],
    [anyone|plyr,"shugo_talk_1",
		[
			(troop_get_slot,':quest_no','$g_conversation_troop',slot_troop_quest),
			(gt,':quest_no',0),
			],
     "About the mission you gave me...","shugo_mission_active_1",[]],
    [anyone,"shugo_mission_active_1",[],"Yes, what about it?","shugo_mission_active_2",[]],
	[anyone|plyr,'shugo_mission_active_2',
		[
			(troop_get_slot,':quest_no','$g_conversation_troop',slot_troop_quest),
			(try_begin),
				(eq,':quest_no','qst_bushi_suppress_rebels'),
				(check_quest_succeeded,':quest_no'),
				(assign,'$g_talk_context',tc_shugo_quest_succeeded),
				(str_store_string,s10,'@The rebels are no more.'),
			(else_try),
				(eq,':quest_no','qst_bushi_defeat_enemy_local_garrisons'),
				(store_num_parties_destroyed_by_player,':num_parties',"pt_local_patrol"),
				(quest_get_slot,':num_parties_defeated',':quest_no',slot_quest_pt_defeated),
				(val_sub,':num_parties',":num_parties_defeated"),
				(ge,':num_parties',1),
				(assign,'$g_talk_context',tc_shugo_quest_succeeded),
				(str_store_string,s10,'@I have eliminated some enemy local garrisons.'),
			(else_try),
				(eq,':quest_no','qst_bushi_reconnoiter_enemy_army'),
				(check_quest_succeeded,':quest_no'),
				(assign,'$g_talk_context',tc_shugo_quest_succeeded),
				(str_store_string,s10,'@I have learned much about the enemy forces.'),
			(else_try),
				(eq,':quest_no','qst_bushi_scout_enemy_patrol'),
				(check_quest_succeeded,':quest_no'),
				(assign,'$g_talk_context',tc_shugo_quest_succeeded),
				(str_store_string,s10,'@I have located the position of an enemy patrol.'),
			(else_try),
				(eq,':quest_no','qst_storyline_bushi_rebellion'),
				(check_quest_succeeded,':quest_no'),
				(assign,'$g_talk_context',tc_shugo_quest_succeeded),
				(str_store_string,s10,'@It was not easy, but I have put down the rebellion.'),
			(else_try),
				(eq,':quest_no','qst_storyline_bushi_establish_outpost'),
				(check_quest_succeeded,':quest_no'),
				(assign,'$g_talk_context',tc_shugo_quest_succeeded),
				(str_store_string,s10,'@The construction of the outpost is complete, and your forces are harassing the enemy.'),
			(else_try),
				(eq,':quest_no','qst_storyline_bushi_enemy_patrols'),
				(check_quest_succeeded,':quest_no'),
				(call_script,'script_get_shugo_faction'),
				(str_store_faction_name,s11,reg1),
				(assign,'$g_talk_context',tc_shugo_quest_succeeded),
				(str_store_string,s10,'@I have laid low many of the {s11} with my own blade.'),
			(else_try),
				(eq,':quest_no','qst_ronin_defeat_bandit_parties'),
				(check_quest_succeeded,':quest_no'),
				(assign,'$g_talk_context',tc_shugo_quest_succeeded),
				(str_store_string,s10,'@Many of the these vermin bandits have fallen beneath my steel.'),
			(else_try),
				(eq,':quest_no','qst_ronin_apprehend_bandits'),
				(eq,':quest_no','qst_ronin_apprehend_bandits'),
				(assign,':total_prisoners',0),
				(party_get_num_prisoner_stacks,':no_prisoner_stacks','p_main_party'),
				(try_for_range,':stack_no',0,':no_prisoner_stacks'),
					(party_prisoner_stack_get_troop_id,':prisoner_troop_id','p_main_party',':stack_no'),
					(this_or_next|is_between,':prisoner_troop_id','trp_bandit','trp_shinobi_apprentice'),
					(eq,':prisoner_troop_id','trp_bandit_warlord'),
					(party_prisoner_stack_get_size,':num_prisoners','p_main_party',':stack_no'),
					(val_add,':total_prisoners',':num_prisoners'),
				(try_end),
				(gt,':total_prisoners',0),
				(assign,'$g_talk_context',tc_shugo_quest_succeeded),
				(str_store_string,s10,'@I have brought some criminals in for questioning.'),
			(else_try),
				(eq,':quest_no','qst_ronin_investigate_bandit_activity'),
				(check_quest_concluded,':quest_no'),
				(try_begin),
					(main_party_has_troop,'trp_bandit_leader'),
					(str_store_string,s12,'@, and present their leader for questioning.'),
				(else_try),
					(str_store_string,s12,'@. Their leader was killed before he could be captured.'),
				(try_end),
				(quest_get_slot,':city','qst_ronin_investigate_bandit_activity',slot_quest_target_party_2),
				(str_store_party_name,1,':city'),
				(assign,'$g_talk_context',tc_shugo_quest_succeeded),
				(str_store_string,s10,'@I have uncovered the group of bandits harrassing {s1}{s12}'),
			(else_try),
				(eq,':quest_no','qst_kuge_emissary'),
				(try_begin),
					(check_quest_succeeded,':quest_no'),
					(assign,'$g_talk_context',tc_shugo_quest_succeeded),
					(str_store_string,s12,'@We continue to find favor with them.'),
				(else_try),
					(check_quest_failed,':quest_no'),
					(assign,'$g_talk_context',tc_shugo_quest_failed),
					(str_store_string,s10,'@We have lost favor with them.'),
				(try_end),
				(str_store_string,s10,'@I have returned from the imperial court. {s12}'),
			(else_try),
				(eq,':quest_no','qst_kuge_entertain_visiting_kuge'),
				(try_begin),
					(call_script,'script_cf_object_flag_set',obj_quest,':quest_no',slot_quest_flags,3),
					(assign,'$g_talk_context',tc_shugo_quest_succeeded),
					(str_store_string,s10,'@Your guest was quite pleased with his gift.'),
				(else_try),
					(call_script,'script_cf_object_flag_set',obj_quest,':quest_no',slot_quest_flags,2),
					(assign,'$g_talk_context',tc_shugo_quest_concluded),
					(str_store_string,s10,'@The noble had a pleasant time.'),
				(else_try),
					(call_script,'script_cf_object_flag_set',obj_quest,':quest_no',slot_quest_flags,1),
					(assign,'$g_talk_context',tc_shugo_quest_failed),
					(str_store_string,s10,'@The kuge was rather displeased with his visit.'),
				(else_try),
					(quest_slot_eq,':quest_no',slot_quest_flags,0),
					(quest_get_slot,':quest_item',':quest_no',slot_quest_item_1),
					(player_has_item,':quest_item'),
					(assign,'$g_talk_context',tc_shugo_quest_proceed),
					(str_store_string,s10,'@I have have the gift for the kuge.'),
				(try_end),
			(try_end),
			],
		'{s10}','shugo_quest_complete',
		[
			]],
	[anyone,'shugo_quest_complete',
		[
			(troop_get_slot,':quest_no','$g_conversation_troop',slot_troop_quest),
			(try_begin),
				(eq,':quest_no','qst_kuge_entertain_visiting_kuge'),
				(try_begin),
					(eq,'$g_talk_context',tc_shugo_quest_succeeded),
					(str_store_string,s10,'@You have done well, {playername}. I am pleased.'),
				(else_try),
					(eq,'$g_talk_context',tc_shugo_quest_concluded),
					(str_store_string,s10,'@Well, the nobles are a fickle bunch.'),
				(else_try),
					(eq,'$g_talk_context',tc_shugo_quest_failed),
					(str_store_string,s10,'@I am angered. Leave now.'),
				(else_try),
					(eq,'$g_talk_context',tc_shugo_quest_proceed),
					(str_store_string,s10,'@Wonderful. Now, we must prepare. He will be arriving soon.'),
				(try_end),
			(else_try),
			
			],
		'{s10}','shugo_quest_complete_2',
		[
			(troop_get_slot,':quest_no','$g_conversation_troop',slot_troop_quest),
			(try_begin),
				(eq,':quest_no','qst_kuge_entertain_visiting_kuge'),
				(eq,'$g_talk_context',tc_shugo_quest_proceed),
				(modify_visitors_at_site,"scn_inn"),
		        (reset_visitors),
		        (set_visitor,3,"$g_conversation_troop"),
		        (set_visitor,6,"trp_kuge"),
		        (set_jump_mission,"mt_entertain_visiting_kuge"),
		        (set_jump_entry,1),
		        (jump_to_scene,"scn_inn"),
		        (change_screen_mission),
			(else_try),
				(eq,'$g_talk_context',tc_shugo_quest_succeeded),
				(call_script,'script_quest_reward',':quest_no'),
				(troop_set_slot,'$g_conversation_troop',slot_troop_quest,null),
				(troop_set_slot,'$g_conversation_troop',slot_troop_quest_active,1),
				(try_begin),
					(neg|check_quest_succeeded,':quest_no'),
					(call_script,'script_succeed_quest',":quest_no"),
				(try_end),
				(call_script,'script_end_quest',':quest_no'),
			(else_try),
				(eq,'$g_talk_context',tc_shugo_quest_concluded),
				(troop_set_slot,'$g_conversation_troop',slot_troop_quest,null),
				(troop_set_slot,'$g_conversation_troop',slot_troop_quest_active,1),
				(call_script,'script_end_quest',':quest_no'),
			(else_try),
				(eq,'$g_talk_context',tc_shugo_quest_failed),
				(troop_set_slot,'$g_conversation_troop',slot_troop_quest,null),
				(troop_set_slot,'$g_conversation_troop',slot_troop_quest_active,1),
				(try_begin),
					(neg|check_quest_failed,':quest_no'),
					(call_script,'script_fail_quest',':quest_no'),
				(try_end),
				(call_script,'script_end_quest',':quest_no'),
				(call_script,'script_object_modify_slot',obj_troop,'trp_player',slot_player_renown,op_sub,5),
			(try_end),
			]],
	[anyone|plyr,"shugo_mission_active_2",[],"I haven't finished it yet.","shugo_quest_continue",[]],
    [anyone,"shugo_quest_continue",[],"Well, get to it. Time is short.","shugo_pre_talk_2",[]],
    [anyone|plyr,"shugo_mission_active_2",[],"I can't finish it.","shugo_quest_complete",
		[
			(assign,'$g_talk_context',tc_shugo_quest_failed),
			]],
	[anyone|plyr,'shugo_quest_complete_2',
		[
			(neq,'$g_talk_context',tc_shugo_quest_failed),
			],
		'You honor me, Tono','shugo_quest_complete_3',[]],
	[anyone,'shugo_quest_complete_3',[],'It is you who honor us, {playername}.','shugo_talk_1',[]],
    [anyone|plyr,'shugo_quest_complete_2',
		[
			(eq,'$g_talk_context',tc_shugo_quest_failed),
			],
		'Yes, Tono. My apologies.','shugo_quest_failed',[]],
	[anyone,'shugo_quest_failed',[],'Just go...and do not fail me again.','close_window',[]],
    [anyone|plyr,"shugo_talk_1",
		[
			(troop_slot_eq,'$g_conversation_troop',slot_troop_quest_active,0),
			],
		"Do you have a mission for me, Tono?","shugo_mission_assign_1",
		[
			(call_script,'script_get_class_quest'),
			(assign,'$shugo_quest',reg0),
			]],
    [anyone,'shugo_mission_assign_1',
     [
         (is_between,'$shugo_quest','qst_storyline_bushi_rebellion','qst_storyline_bushi_rebellion_2'),
		 (call_script,'script_get_shugo_faction'),
         (str_store_faction_name,1,reg1),
         (quest_get_slot,':dialog','$shugo_quest',slot_quest_shugo_dialog),
         (str_store_string,2,':dialog')],
     'Yes, {playername}. I have something of the utmost importance. {s2}','shugo_quest_accept',[]],
	[anyone,'shugo_mission_assign_1',
		[
			(eq,'$shugo_quest','qst_ronin_defeat_bandit_parties'),
			],
		'The bandit menace has gotten out of control. Go out and eliminate as many as possible.','shugo_quest_accept',[]],
    [anyone,'shugo_mission_assign_1',
		[
			(eq,'$shugo_quest','qst_ronin_apprehend_bandits'),
			],
		'We need more information about the movements of the bandit scum. Return to me with some of their ilk in tow.','shugo_quest_accept',[]],
    [anyone,'shugo_mission_assign_1',
		[
			(eq,'$shugo_quest','qst_ronin_investigate_bandit_activity'),
			#(assign,':break_loop',false),
			(store_random_in_range,':target_city',hyogo,cities_end),
			(quest_set_slot,'qst_ronin_investigate_bandit_activity',slot_quest_party_1,':target_city'),
			(str_store_party_name,10,':target_city'),
			],
		'A minor bandit leader has been causing trouble near {s10}. Go there, question the locals, and root out these troublemakers. If you can bring me the leader alive, there will be an extra award.','shugo_quest_accept',[]],
    [anyone,"shugo_mission_assign_1",
	[
		(eq,'$shugo_quest','qst_bushi_suppress_rebels'),
		(call_script,'script_get_shugo_faction'),
		(assign,':shugo_faction',reg0),
		(call_script,'script_select_random_faction_village',':shugo_faction'),
		(quest_set_slot,'$shugo_quest',slot_quest_target_party,'$return'),
		(str_store_party_name,1,"$return"),
		],
     "Yes. Some of the peasants and a few upstart monks are causing trouble near {s1}. Go there, and deal with them.",
     "shugo_quest_accept",[]],
    [anyone,"shugo_mission_assign_1",[(this_or_next|eq,"$shugo_quest","qst_kuge_war_materials"),
                                      (eq,"$shugo_quest","qst_bushi_war_materials"),
                                      (quest_set_slot,'$shugo_quest',slot_quest_giver,'$g_conversation_troop'),
                                      (store_troop_faction,':faction','$g_conversation_troop'),
                                      (store_free_inventory_capacity,':inv_cap',"trp_player"),
                                      (ge,':inv_cap',1),
                                      (store_random_in_range,':quest_item',"itm_kozane","itm_string_of_coins"),
                                      (quest_set_slot,'$shugo_quest',slot_quest_item_1,':quest_item'),
                                      (str_store_item_name,1,':quest_item'),
                                      (try_begin),
                                          (eq,':faction',"fac_hosokawa"),
                                          (store_random_in_range,':target_troop',"trp_takase_shugo","trp_hidaka_shugo"),
                                      (else_try),
                                          (eq,':faction',"fac_yamana"),
                                          (store_random_in_range,':target_troop',"trp_hidaka_shugo","trp_city_1_kokujin"),
                                      (try_end),
                                      (neq,':target_troop','$g_conversation_troop'),
                                      (quest_set_slot,'$shugo_quest',slot_quest_target_troop,':target_troop'),
                                      (store_random_in_range,':days_to_completion',0,4),
                                      (val_add,':days_to_completion',4),
                                      (quest_set_slot,"$shugo_quest",slot_quest_time_to_completion,':days_to_completion'),
									  (assign,reg10,':days_to_completion'),
                                      (troop_get_slot,':target_city',':target_troop',slot_troop_city),
                                      (quest_set_slot,'$shugo_quest',slot_quest_target_party,':target_city'),
                                      (str_store_party_name,3,':target_city'),
                                      (str_store_troop_name,2,':target_troop')],
     "Yes. You are to deliver this shipment of {s1} to {s2} in {s3} within {reg10} days.","shugo_quest_accept",[]],
    [anyone,"shugo_mission_assign_1",[(eq,"$shugo_quest","qst_bushi_defeat_enemy_local_garrisons")],
     "Yes. The enemy has begun fielding more patrols around their villages. Eliminate as many as you can.",
     "shugo_quest_accept",[]],
    [anyone,"shugo_mission_assign_1",[(eq,"$shugo_quest","qst_bushi_reconnoiter_enemy_army")],
     "Yes. My scouts have discovered two enemy armys near Kyoto. We need more information about the enemy's troop strength. Find and reconnoiter an enemy army. Do not engage them, however.",
     "shugo_quest_accept",[]],
    [anyone,"shugo_mission_assign_1",[(eq,"$shugo_quest","qst_kuge_emissary"),
                                        (store_troop_faction,reg2,'$g_conversation_troop'),
                                        (try_begin),
                                            (eq,reg2,"fac_hosokawa"),
                                            (str_store_string,1,"str_hosokawa"),
                                        (else_try),
                                            (eq,reg2,"fac_yamana"),
                                            (str_store_string,1,"str_yamana"),
                                        (try_end)],
     "Yes. It is important that we maintain our ties with the imperial court. You will travel there and represent the {s1}.",
     "shugo_quest_accept",[]],
    [anyone,"shugo_mission_assign_1",[(eq,"$shugo_quest","qst_kuge_entertain_visiting_kuge"),
                                        (store_random_in_range,"$kuge_type",0,5),
                                        (val_add,"$kuge_type",1)],
    "A kuge is traveling to visit and I wish to entertain him. However, I am really just a samurai, and know little about the finer things a kuge would enjoy. You must help me properly entertain my guest!",
    "visiting_kuge_1",[]],
    [anyone|plyr,"visiting_kuge_1",[],"Of course. What sort of man is this kuge?","visiting_kuge_2",[]],
    [anyone,"visiting_kuge_2",[(try_begin),
                                    (eq,"$kuge_type",1),
                                    (str_store_string,1,"str_kuge_type_1"),
                                (else_try),
                                    (eq,"$kuge_type",2),
                                    (str_store_string,1,"str_kuge_type_2"),
                                (else_try),
                                    (eq,"$kuge_type",3),
                                    (str_store_string,1,"str_kuge_type_3"),
                                (else_try),
                                    (eq,"$kuge_type",4),
                                    (str_store_string,1,"str_kuge_type_4"),
                                (else_try),
                                    (eq,"$kuge_type",5),
                                    (str_store_string,1,"str_kuge_type_5"),
                                (try_end)],
    "{s1}","visiting_kuge_3",[]],
    [anyone,"visiting_kuge_3",[],"What do you suggest?","visiting_kuge_4",[]],
    [anyone|plyr,"visiting_kuge_4",[],"I would suggest a painting by Sesshu himself.","visiting_kuge_5",
     [(quest_set_slot,'$shugo_quest',slot_quest_item_1,"itm_sesshu_painting")]],
    [anyone|plyr,"visiting_kuge_4",[],"I would imagine his copy is getting old. Let us give a new copy of Genji Monogatari.","visiting_kuge_5",
     [(quest_set_slot,'$shugo_quest',slot_quest_item_1,"itm_genji_monogatari")]],
    [anyone|plyr,"visiting_kuge_4",[],"He would appreciate a fine calligraphy scroll.","visiting_kuge_5",
     [(quest_set_slot,'$shugo_quest',slot_quest_item_1,"itm_calligraphy_scrolls")]],
    [anyone|plyr,"visiting_kuge_4",[],"We should give him a fine piece of pottery.","visiting_kuge_5",
     [(quest_set_slot,'$shugo_quest',slot_quest_item_1,"itm_elaborate_pottery")]],
    [anyone|plyr,"visiting_kuge_4",[],"Only a well-decorated roll of Chinese silk will please him.","visiting_kuge_5",
     [(quest_set_slot,'$shugo_quest',slot_quest_item_1,"itm_chinese_silk")]],
    [anyone,"visiting_kuge_5",[(quest_get_slot,reg1,'$shugo_quest',slot_quest_item_1),(str_store_item_name,1,reg1)],
    "Excellent! The kuge is arriving soon, so you must bring one {s1} quickly.","shugo_quest_accept",[]],
    [anyone,"shugo_mission_assign_1",
		[
			(troop_set_slot,'$g_conversation_troop',slot_troop_quest,null),
			# (troop_set_slot,'$g_conversation_troop',slot_troop_quest_active,1),
			],
     "I have nothing for you now. Try again tomorrow.","shugo_pre_talk_2",[]],
    [anyone|plyr,'shugo_quest_accept',[],"I will bring honor to you, or die trying.",'shugo_pre_talk_2',
		[
			(call_script,'script_shugo_quest_accept','$shugo_quest','$g_conversation_troop'),
			]],
    [anyone|plyr,"shugo_talk_1",[],"About my rank and wages...","shugo_wages_1",[]],
	[anyone,'shugo_wages_1',[],'{s10}','shugo_collect_wages',
		[
			(troop_get_slot,':rank_array','trp_player',slot_player_rank_array),
			(troop_get_slot,':rank_array_ptr','trp_player',slot_player_rank_ptr),
			(call_script,'script_get_rank_pay_and_fp_rate',':rank_array',':rank_array_ptr'),
			(assign,reg10,reg0),
			(call_script,'script_get_rank_title',':rank_array',':rank_array_ptr'),
			(assign,':title',reg0),
			(str_store_string,s11,':title'),
			(str_store_string,s10,'@Well, you are a {s11} for our army, and as such your weekly wage is {reg10} mon.'),
			]],
    [anyone,"shugo_collect_wages",
		[
			(troop_get_slot,':rank_array','trp_player',slot_player_rank_array),
			(troop_get_slot,':rank_array_ptr','trp_player',slot_player_rank_ptr),
			(call_script,'script_get_rank_wages',':rank_array',':rank_array_ptr'),
			(eq,reg0,0),
			],
		"You have no wages accumulated yet.","shugo_pre_talk_2",[]],
    [anyone,"shugo_collect_wages",[],"By the way, your wages have accumulated to some {reg2} mon. Well here you go.","shugo_pre_talk_2",
		[
			(troop_get_slot,':rank_array','trp_player',slot_player_rank_array),
			(troop_get_slot,':rank_array_ptr','trp_player',slot_player_rank_ptr),
			(call_script,'script_get_rank_wages',':rank_array',':rank_array_ptr'),
			(assign,':wages',reg0),
			(assign,reg2,':wages'),
			(call_script,'script_get_rank_fp',':rank_array',':rank_array_ptr'),
			(assign,':fp',reg0),
			(call_script,'script_set_rank_wages',':rank_array',':rank_array_ptr',0),
			(call_script,'script_set_rank_fp',':rank_array',':rank_array_ptr',0),
			(troop_add_gold,"trp_player",":wages"),
			(call_script,'script_object_modify_slot',obj_troop,'trp_player',slot_player_faction_points,op_add,':fp'),
			]],
    [anyone|plyr,"shugo_talk_1",
		[
			(neg|check_quest_active,'qst_subclass_monk'),
			],
		"I need to retain some troops.","shugo_troops_1",
		[
			(party_get_free_companions_capacity,'$available_troop_capacity','p_main_party'),
			]],
    [anyone,"shugo_troops_1",[],"Do you require samurai or ashigaru?","shugo_troops_2",[]],
    [anyone|plyr,"shugo_troops_2",[],"Samurai","shugo_troops_3",[]],
    [anyone,"shugo_troops_3",
     [(lt,'$available_troop_capacity',1)],
     "You do not have enough room in your party retain any samurai.","shugo_pre_talk_2",[]],
    [anyone,"shugo_troops_3",
		[
			(troop_slot_lt,"trp_player",slot_player_faction_points,2),
			],
		"You do not have enough influence to retain any samurai.","shugo_pre_talk_2",[]],
    [anyone,"shugo_troops_3",
		[
			(troop_slot_ge,"trp_player",slot_player_faction_points,2),
			(troop_get_slot,'$current_fp','trp_player',slot_player_faction_points),
			],
		"I have several young bushi willing to go with you. Who do you wish to retain?","shugo_troops_4",[]],
    [anyone|plyr,"shugo_troops_4",[],"Samurai: 360 mon/2 FP","shugo_troops_5",
     [(try_begin),
          (store_partner_faction,reg2),
          (eq,reg2,"fac_hosokawa"),
          (assign,"$troop_to_hire","trp_samurai"),
          (assign,"$troop_hiring_cost",360),
          (assign,"$troop_fp_cost",2),
      (else_try),
          (store_partner_faction,reg2),
          (eq,reg2,"fac_yamana"),
          (assign,"$troop_to_hire","trp_samurai"),
          (assign,"$troop_hiring_cost",360),
          (assign,"$troop_fp_cost",2),
      (try_end)]],
    [anyone|plyr,"shugo_troops_4",[],"Yumi samurai: 720 mon/5 FP","shugo_troops_5",
     [(try_begin),
          (store_partner_faction,reg2),
          (eq,reg2,"fac_hosokawa"),
          (assign,"$troop_to_hire","trp_t2_bow_ashigaru_h"),
          (assign,"$troop_hiring_cost",720),
          (assign,"$troop_fp_cost",5),
      (else_try),
          (store_partner_faction,reg2),
          (eq,reg2,"fac_yamana"),
          (assign,"$troop_to_hire","trp_t2_bow_ashigaru_y"),
          (assign,"$troop_hiring_cost",720),
          (assign,"$troop_fp_cost",5),
      (try_end)]],
    [anyone|plyr,"shugo_troops_4",[],"Foot samurai: 540 mon/3 FP","shugo_troops_5",
     [(try_begin),
          (store_partner_faction,reg2),
          (eq,reg2,"fac_hosokawa"),
          (assign,"$troop_to_hire","trp_t2_spear_samurai_h"),
          (assign,"$troop_hiring_cost",540),
          (assign,"$troop_fp_cost",3),
      (else_try),
          (store_partner_faction,reg2),
          (eq,reg2,"fac_yamana"),
          (assign,"$troop_to_hire","trp_t2_sword_samurai_y"),
          (assign,"$troop_hiring_cost",540),
          (assign,"$troop_fp_cost",3),
      (try_end)]],
    [anyone|plyr,"shugo_troops_4",[],"Never mind.","shugo_pre_talk_2",[]],
    [anyone,"shugo_troops_5",[(lt,'$available_troop_capacity',1)],"I'm afraid you don't have room.","shugo_pre_talk_2",[]],
    [anyone,"shugo_troops_5",[(ge,'$available_troop_capacity',1)],"How many do you need to retain?","shugo_troops_6",[]],
    [anyone|plyr,"shugo_troops_6",
     [
         (store_troop_gold,reg2,"trp_player"),
         (ge,'$available_troop_capacity',1),
         (ge,reg2,"$troop_hiring_cost"),
         (ge,"$current_fp","$troop_fp_cost"),
         ],
     "One.","shugo_troops_7",[(assign,"$num_troops_to_hire",1),]],
    [anyone|plyr,"shugo_troops_6",
     [
         (store_troop_gold,reg1,"trp_player"),
         (assign,reg2,"$troop_hiring_cost"),
         (assign,reg3,"$troop_fp_cost"),
         (val_mul,reg2,3),
         (val_mul,reg3,3),
         (ge,'$available_troop_capacity',3),
         (ge,reg1,reg2),
         (ge,"$current_fp",reg3),
         ],
     "Three.","shugo_troops_7",[(assign,"$num_troops_to_hire",3),
                                (val_mul,"$troop_hiring_cost",3),
                                (val_mul,"$troop_fp_cost",3),]],
    [anyone|plyr,"shugo_troops_6",
     [
         (store_troop_gold,reg1,"trp_player"),
         (assign,reg2,"$troop_hiring_cost"),
         (assign,reg3,"$troop_fp_cost"),
         (val_mul,reg2,5),
         (val_mul,reg3,5),
         (ge,'$available_troop_capacity',5),
         (ge,reg1,reg2),
         (ge,"$current_fp",reg3),
         ],
     "Five.","shugo_troops_7",[(assign,"$num_troops_to_hire",5),
                               (val_mul,"$troop_hiring_cost",5),
                               (val_mul,"$troop_fp_cost",5)]],
    [anyone|plyr,"shugo_troops_6",[],"Never mind.","shugo_pre_talk_2",[]],
    [anyone,"shugo_troops_7",[],"Very well. {reg1} {s1} join your party.","shugo_pre_talk_2",
		[
			(troop_remove_gold,"trp_player","$troop_hiring_cost"),
			(call_script,"script_sub_faction_points",'$troop_fp_cost'),
			(party_add_members,"p_main_party","$troop_to_hire","$num_troops_to_hire"),
			(assign,reg1,"$num_troops_to_hire"),
			(str_store_troop_name,1,"$troop_to_hire"),
			]],
    [anyone|plyr,"shugo_troops_2",[],"Ashigaru","shugo_troops_10",[]],
    [anyone,"shugo_troops_10",[],"Sure. Have a look at the new recruits.","shugo_pre_talk_2",
     [(store_partner_faction,reg1),
      (try_begin),
          (eq,reg1,'fac_hosokawa'),
          (set_mercenary_source_party,"p_hosokawa_mercs"),
      (else_try),
          (eq,reg1,"fac_yamana"),
          (set_mercenary_source_party,"p_yamana_mercs"),
      (try_end),
      (change_screen_buy_mercenaries,0)]],
    [anyone|plyr,"shugo_talk_1",[],"I take my leave of you, Tono.","shugo_talk_end",[]],
    [anyone,"shugo_talk_end",[],"Very well, {playername}. Bring honor to us!","close_window",[]],
#Intro kuge quest dialogs
    [trp_bandit_warlord,"start",[],"Don't even think about trying to escape.","kuge_bandits_1",[]],
    [anyone|plyr,"kuge_bandits_1",[],"I wouldn't think of it. What do you want?","kuge_bandits_2",[]],
    [anyone,"kuge_bandits_2",[(store_attribute_level,reg1,"trp_player",3),
                              (ge,reg1,9)],
     "I'm feeling generous today. I'll let you go for 100 mon.","kuge_bandits_3",[]],
    [anyone,"kuge_bandits_2",[(store_attribute_level,reg1,"trp_player",3),
                              (lt,reg1,9)],
     "You won't leave here for less than 150 mon.","kuge_bandits_4",[]],
    [anyone|plyr,"kuge_bandits_3",[(store_troop_gold,reg1,"trp_player"),
                                   (ge,reg1,100)],
     "Very well. Here is your 100 mon.","kuge_bandits_end",[(troop_remove_gold,"trp_player",100)]],
    [anyone|plyr,"kuge_bandits_3",[],"That's rididulous. I won't pay it.","kuge_bandits_fight",[]],
    [anyone|plyr,"kuge_bandits_4",[(store_troop_gold,reg1,"trp_player"),
                                   (ge,reg1,150)],
     "Very well. Here is your 150 mon.","kuge_bandits_end",[(troop_remove_gold,"trp_player",150)]],
    [anyone|plyr,"kuge_bandits_4",[],"That's rididulous. I won't pay it.","kuge_bandits_fight",[]],
    [anyone,"kuge_bandits_end",[(assign,"$ikq_negotiate",1)],"You have made a wise decision.","close_window",[]],
    [anyone,"kuge_bandits_fight",[],"Then I will take it out of your hide.","close_window",[(set_party_battle_mode),
                                              (set_jump_mission,"mt_ikq_fight"),
                                              (jump_to_scene,"scn_random_scene"),
                                              (change_screen_mission,0)]],
#Hosokawa/Yamana party dialogs
	[anyone,'start',
		[
			(eq,'$g_talk_context',tc_ally_thanks),
			],
		'Thanks for the help back there.','close_window',
		[
			(assign,'$g_leave_encounter',true),
			]],
	[anyone,'start',
		[
			(eq,'$g_encountered_party_template','pt_spy'),
			],
		'Please excuse us. We must be on our way.','close_window',
		[
			(assign,'$g_leave_encounter',true),
			]],
	[anyone,'start',
		[
			(this_or_next|eq,'$g_encountered_party_template','pt_hosokawa_foragers'),
			(this_or_next|eq,'$g_encountered_party_template','pt_hosokawa_scouts'),
			(this_or_next|eq,'$g_encountered_party_template','pt_hosokawa_raiders'),
			(this_or_next|eq,'$g_encountered_party_template','pt_hosokawa_patrol'),
			(eq,'$g_encountered_party_template','pt_hosokawa_war_party'),
			(eq,'$g_talk_context',tc_party_encounter),
			(party_get_slot,'$g_encountered_party_attitude','$g_encountered_party',slot_spawn_att_to_player),
			(str_clear,s10),
			(try_begin),
				(eq,'$g_encountered_party_template','pt_hosokawa_foragers'),
				(str_store_string,s10,'@Greetings, traveller...'),
			(else_try),
				(eq,'$g_encountered_party_template','pt_hosokawa_scouts'),
				(str_store_string,s10,'@Hail! What have you seen?'),
			(else_try),
				(eq,'$g_encountered_party_template','pt_hosokawa_raiders'),
				(str_store_string,s10,'@Halt! Who goes there?'),
			(else_try),
				(eq,'$g_encountered_party_template','pt_hosokawa_patrol'),
				(str_store_string,s10,'@Halt! Who goes there?'),
			(else_try),
				(eq,'$g_encountered_party_template','pt_hosokawa_war_party'),
				(str_store_string,s10,'@Halt! Who goes there?'),
			(try_end),
			],
		'{s10}','hosokawa_spawn_1',
		[
			(try_begin),
				(eq,'$g_encountered_party_attitude',att_cautious),
				(assign,'$g_talk_context',tc_spawn_enc_neutral),
			(else_try),
				(gt,'$g_encountered_party_attitude',att_cautious),
				(assign,'$g_talk_context',tc_spawn_enc_favorable),
			(else_try),
				(lt,'$g_encountered_party_attitude',att_cautious),
				(assign,'$g_talk_context',tc_spawn_enc_unfavorable),
			(try_end),
			]],
	[anyone|plyr|repeat_for_troops,'hosokawa_spawn_1',
		[
			(store_repeat_object,'$g_dialog_state'),
			(is_between,'$g_dialog_state',100,104),
			(party_get_slot,'$g_encountered_party_attitude','$g_encountered_party',slot_spawn_att_to_player),
			(str_clear,s10),
			(try_begin),
				(eq,'$g_encountered_party_template','pt_hosokawa_foragers'),
				(try_begin),
					(eq,'$g_dialog_state',ds_friendly),
					(str_store_string,s10,'@And also to you. Please forgive me, but I must be on my way.'),
				(else_try),
					(this_or_next|eq,'$g_dialog_state',ds_neutral),
					(eq,'$g_dialog_state',ds_cowardly),
					(str_store_string,s10,'@Indeed. I am simply passing through.'),
				(else_try),
					(eq,'$g_dialog_state',ds_combative),
					(str_store_string,s10,"@You'll wish you had not met me"),
				(try_end),
			(else_try),
				(eq,'$g_encountered_party_template','pt_hosokawa_scouts'),
				(try_begin),
					(eq,'$g_dialog_state',ds_friendly),
					(str_store_string,s10,'@Nothing, really. Please forgive me, but I must be on my way.'),
				(else_try),
					(this_or_next|eq,'$g_dialog_state',ds_neutral),
					(eq,'$g_dialog_state',ds_cowardly),
					(str_store_string,s10,'@I have seen nothing. I am simply passing through.'),
				(else_try),
					(eq,'$g_dialog_state',ds_combative),
					(str_store_string,s10,'@Indeed. I am simply passing through.'),
				(try_end),
			(else_try),
				(this_or_next|eq,'$g_encountered_party_template','pt_hosokawa_raiders'),
				(this_or_next|eq,'$g_encountered_party_template','pt_hosokawa_patrol'),
				(eq,'$g_encountered_party_template','pt_hosokawa_war_party'),
				(try_begin),
					(eq,'$g_dialog_state',ds_friendly),
					(str_store_string,s10,'@I am {playername}'),
				(else_try),
					(eq,'$g_dialog_state',ds_neutral),
					(str_store_string,s10,'@No one. I am simply passing through.'),
				(else_try),
					(eq,'$g_dialog_state',ds_combative),
					(str_store_string,s10,'@I am {playername}, and none shall survive the day.'),
				(else_try),
					(eq,'$g_dialog_state',ds_cowardly),
					(str_store_string,s10,'@I am no one of importance. Please, let me pass.'),
				(try_end),
			(try_end),
			],
		'{s10}','hosokawa_spawn_2',
		[
			(store_repeat_object,'$g_dialog_state'),
			]],
	[anyone,'hosokawa_spawn_2',
		[
			(str_clear,s10),
			(try_begin),
				(eq,'$g_encountered_party_template','pt_hosokawa_foragers'),
				(try_begin),
					(ge,'$g_encountered_party_attitude',att_cautious),
					(try_begin),
						(this_or_next|eq,'$g_dialog_state',ds_friendly),
						(this_or_next|eq,'$g_dialog_state',ds_neutral),
						(eq,'$g_dialog_state',ds_cowardly),
						(assign,'$g_leave_encounter',true),
						(str_store_string,s10,'@Very well. Good day, then.'),
					(else_try),
						(str_store_string,s10,'@Murderous fiend! To arms!'),
						(party_set_slot,'$g_encountered_party',slot_spawn_att_to_player,att_hostile),
					(try_end),
				(else_try),
					(lt,'$g_encountered_party_attitude',att_cautious),
					(try_begin),
						(eq,'$g_dialog_state',ds_friendly),
						(str_store_string,s10,'@I know who you are. Be gone.'),
						(assign,'$g_leave_encounter',true),
					(else_try),
						(eq,'$g_dialog_state',ds_neutral),
						(str_store_string,s10,'@I will enjoy watching you die.'),
						(party_set_slot,'$g_encountered_party',slot_spawn_att_to_player,att_hostile),
					(else_try),
						(eq,'$g_dialog_state',ds_combative),
						(str_store_string,s10,'@I will enjoy watching you die.'),
						(party_set_slot,'$g_encountered_party',slot_spawn_att_to_player,att_hostile),
					(else_try),
						(eq,'$g_dialog_state',ds_cowardly),
						(str_store_string,s10,'@I will enjoy watching you die, coward.'),
						(party_set_slot,'$g_encountered_party',slot_spawn_att_to_player,att_hostile),
					(try_end),
				(try_end),
			(else_try),
				(eq,'$g_encountered_party_template','pt_hosokawa_scouts'),
				(try_begin),
					(eq,'$g_encountered_party_attitude',att_cautious),
					(try_begin),
						(this_or_next|eq,'$g_dialog_state',ds_friendly),
						(this_or_next|eq,'$g_dialog_state',ds_neutral),
						(eq,'$g_dialog_state',ds_cowardly),
						(assign,'$g_leave_encounter',true),
						(str_store_string,s10,'@Very well. Good day, then.'),
					(else_try),
						(str_store_string,s10,'@Murderous fiend! To arms!'),
						(party_set_slot,'$g_encountered_party',slot_spawn_att_to_player,att_hostile),
					(try_end),
				(else_try),
					(lt,'$g_encountered_party_attitude',att_cautious),
					(try_begin),
						(eq,'$g_dialog_state',ds_friendly),
						(str_store_string,s10,'@I know who you are. Be gone.'),
						(assign,'$g_leave_encounter',true),
					(else_try),
						(eq,'$g_dialog_state',ds_neutral),
						(str_store_string,s10,'@I will enjoy watching you die.'),
						(party_set_slot,'$g_encountered_party',slot_spawn_att_to_player,att_hostile),
					(else_try),
						(eq,'$g_dialog_state',ds_combative),
						(str_store_string,s10,'@I will enjoy watching you die.'),
						(party_set_slot,'$g_encountered_party',slot_spawn_att_to_player,att_hostile),
					(else_try),
						(eq,'$g_dialog_state',ds_cowardly),
						(str_store_string,s10,'@I will enjoy watching you die, coward.'),
						(party_set_slot,'$g_encountered_party',slot_spawn_att_to_player,att_hostile),
					(try_end),
				(try_end),
			(else_try),
				(this_or_next|eq,'$g_encountered_party_template','pt_hosokawa_raiders'),
				(this_or_next|eq,'$g_encountered_party_template','pt_hosokawa_patrol'),
				(eq,'$g_encountered_party_template','pt_hosokawa_war_party'),
				(try_begin),
					(eq,'$g_encountered_party_attitude',att_cautious),
					(try_begin),
						(this_or_next|eq,'$g_dialog_state',ds_friendly),
						(this_or_next|eq,'$g_dialog_state',ds_neutral),
						(eq,'$g_dialog_state',ds_cowardly),
						(assign,'$g_leave_encounter',true),
						(str_store_string,s10,'@Very well. Good day, then.'),
					(else_try),
						(str_store_string,s10,'@Murderous fiend! To arms!'),
						(party_set_slot,'$g_encountered_party',slot_spawn_att_to_player,att_hostile),
					(try_end),
				(else_try),
					(gt,'$g_encountered_party_attitude',att_cautious),
					(try_begin),
						(this_or_next|eq,'$g_dialog_state',ds_friendly),
						(this_or_next|eq,'$g_dialog_state',ds_neutral),
						(eq,'$g_dialog_state',ds_cowardly),
						(assign,'$g_leave_encounter',true),
						(str_store_string,s10,'@Very well. Good day, then.'),
					(else_try),
						(str_store_string,s10,'@Murderous fiend! To arms!'),
						(party_set_slot,'$g_encountered_party',slot_spawn_att_to_player,att_hostile),
					(try_end),
				(else_try),
					(lt,'$g_encountered_party_attitude',att_cautious),
					(try_begin),
						(eq,'$g_dialog_state',ds_friendly),
						(str_store_string,s10,'@I know who you are. I will take your head myself!'),
					(else_try),
						(eq,'$g_dialog_state',ds_neutral),
						(str_store_string,s10,'@I will enjoy watching you die.'),
						(party_set_slot,'$g_encountered_party',slot_spawn_att_to_player,att_hostile),
					(else_try),
						(eq,'$g_dialog_state',ds_combative),
						(str_store_string,s10,'@I will enjoy watching you die.'),
						(party_set_slot,'$g_encountered_party',slot_spawn_att_to_player,att_hostile),
					(else_try),
						(eq,'$g_dialog_state',ds_cowardly),
						(str_store_string,s10,'@I will enjoy watching you die, coward.'),
						(party_set_slot,'$g_encountered_party',slot_spawn_att_to_player,att_hostile),
					(try_end),
				(try_end),
			(try_end),
			],
		'{s10}','close_window',
		[
			(try_begin),
				(eq,'$g_leave_encounter',false),
				(store_faction_of_party,':faction','$g_encountered_party'),
		        (party_get_template_id,':template','$g_encountered_party'),
				(try_begin),
					(eq,':template',"pt_hosokawa_foragers"),
					(assign,':value',-1),
		        (else_try),
		            (eq,':template',"pt_hosokawa_scouts"),
		            (assign,':value',-2),
		        (else_try),
		            (eq,':template',"pt_hosokawa_patrol"),
		            (assign,':value',-3),
		        (else_try),
		            (eq,':template',"pt_hosokawa_war_party"),
		            (assign,':value',-5),
		        (try_end),
		        (call_script,"script_modify_relation_with_player",':faction',':value'),
			(try_end),
			]],
	[anyone,'start',
		[
			(this_or_next|eq,'$g_encountered_party_template','pt_yamana_foragers'),
			(this_or_next|eq,'$g_encountered_party_template','pt_yamana_scouts'),
			(this_or_next|eq,'$g_encountered_party_template','pt_yamana_raiders'),
			(this_or_next|eq,'$g_encountered_party_template','pt_yamana_patrol'),
			(eq,'$g_encountered_party_template','pt_yamana_war_party'),
			(eq,'$g_talk_context',tc_party_encounter),
			(try_begin),
				(eq,'$g_encountered_party_template','pt_yamana_foragers'),
				(str_store_string,s10,'@Greetings, traveler...'),
			(else_try),
				(eq,'$g_encountered_party_template','pt_yamana_scouts'),
				(str_store_string,s10,'@Hail! Have you seen anything nearby?'),
			(else_try),
				(this_or_next|eq,'$g_encountered_party_template','pt_yamana_patrol'),
				(this_or_next|eq,'$g_encountered_party_template','pt_yamana_raiders'),
				(eq,'$g_encountered_party_template','pt_yamana_war_party'),
				(str_store_string,s10,'@Halt! Who goes there?'),
			(try_end),
			],
		'{s10}','yamana_interrogation_1',[]],
    [anyone|plyr,"yamana_interrogation_1",[],"I am simply passing through.","yamana_interrogation_2",[]],
    [anyone,"yamana_interrogation_2",[(party_slot_ge,'$g_encountered_party',slot_spawn_att_to_player,att_friendly)],
     "Indeed. Beware, the enemy could be anywhere.","close_window",[(assign,'$g_leave_encounter',1)]],
    [anyone,"yamana_interrogation_2",[(party_slot_eq,'$g_encountered_party',slot_spawn_att_to_player,att_cautious)],
     "Be careful, there's a war going on.","close_window",[(assign,'$g_leave_encounter',1)]],
    [anyone,"yamana_interrogation_2",
		[
			(party_slot_lt,'$g_encountered_party',slot_spawn_att_to_player,att_cautious),
			],
		"Deceiver! I will take your head myself.","close_window",
		[
			(store_faction_of_party,':faction','$g_encountered_party'),
	        (party_get_template_id,':template','$g_encountered_party'),
			(try_begin),
				(eq,':template',"pt_yamana_foragers"),
				(assign,':value',-1),
	        (else_try),
	            (eq,':template',"pt_yamana_scouts"),
	            (assign,':value',-2),
	        (else_try),
	            (eq,':template',"pt_yamana_patrol"),
	            (assign,':value',-3),
	        (else_try),
	            (eq,':template',"pt_yamana_war_party"),
	            (assign,':value',-5),
	        (try_end),
	        (call_script,"script_modify_relation_with_player",':faction',':value')
			]],
	[anyone,'start',
		[
			(eq,'$g_encountered_party_template','pt_army'),
			(eq,'$g_talk_context',tc_party_encounter),
			(party_get_slot,':attitude','$g_encountered_party',slot_spawn_att_to_player),
			(try_begin),
				(gt,':attitude',att_cautious),
				(assign,'$g_leave_encounter',true),
				(str_store_string,s10,'@I hope it goes well with you. Good day.'),
			(else_try),
				(eq,':attitude',att_cautious),
				(assign,'$g_leave_encounter',true),
				
				(str_store_string,s10,'@I have no time for you. Good day.'),
			(else_try),
				(lt,':attitude',att_cautious),
				
				(str_store_string,s10,'@Finally, I will have your head!'),
			(try_end),
			],
		'{s10}','close_window',
		[
			(try_begin),
				(eq,'$g_leave_encounter',false),
				(store_faction_of_party,':faction','$g_encountered_party'),
				(call_script,"script_modify_relation_with_player",':faction',-10),
			(try_end),
			]],
#Local patrol dialogs
    [anyone,'start',
		[
			(eq,'$g_talk_context',tc_party_encounter),
			(eq,'$g_encountered_party_template','pt_local_patrol'),
			(party_get_slot,'$g_encountered_party_attitude','$g_encountered_party',slot_spawn_att_to_player),
			(assign,reg1,'$g_encountered_party_attitude'),
			(call_script,'script_display_attitude','$g_encountered_party_attitude'),
			],
     "Halt! Who goes there? By the way, our attitude is {reg1}.",'lp_1',[]],
    [anyone|plyr,"lp_1",[],"I am just a simple traveller.","lp_2",[]],
    [anyone|plyr,"lp_1",[],"I am {playername}.","lp_3",[]],
    [anyone,'lp_2',[(ge,'$g_encountered_party_attitude',att_friendly)],
     "Indeed. Beware of our enemies.","close_window",[(assign,'$g_leave_encounter',1)]],
    [anyone,'lp_2',[(eq,'$g_encountered_party_attitude',att_cautious)],
     "Very well. You may pass.","close_window",[(assign,'$g_leave_encounter',1)]],
    [anyone,'lp_2',[(eq,'$g_encountered_party_attitude',att_secretive),
                    (store_faction_of_party,':encountered_party_faction','$g_encountered_party'),
					(call_script,'script_get_shugo_faction'),
                    (neq,':encountered_party_faction',reg1)],
     "Very well. You may pass.","close_window",
     [(assign,'$g_leave_encounter',1)]],
    [anyone,'lp_2',[(eq,'$g_encountered_party_attitude',att_secretive),
                    (store_faction_of_party,':encountered_party_faction','$g_encountered_party'),
					(call_script,'script_get_shugo_faction'),
                    (eq,':encountered_party_faction',reg1),
                    (party_get_slot,':origin','$g_encountered_party',slot_spawn_origin),
                    (call_script,'script_modify_town_fame',':origin',-2),
                    (call_script,'script_modify_relation_with_player',reg2,-2),
                    (party_set_slot,'$g_encountered_party',slot_spawn_att_to_player,att_hostile)],
     "Liar! I will have your head!","close_window",
     [(encounter_attack,0)]],
    [anyone,"lp_2",[(le,'$g_encountered_party_attitude',att_defensive),
                    (party_get_slot,':origin','$g_encountered_party',slot_spawn_origin),
                    (call_script,'script_modify_town_fame',':origin',-5),
                    (store_faction_of_party,reg2,'$g_encountered_party'),
                    (call_script,'script_modify_relation_with_player',reg2,-2),
                    (party_set_slot,'$g_encountered_party',slot_spawn_att_to_player,att_hostile)],
     "Liar! I will have your head!","close_window",[(encounter_attack,0)]],
    [anyone,'lp_3',[(ge,'$party_attitude',att_cautious)],"Well met, {tono/hime}. Be cautious on your journey.",'close_window',[(assign,'$g_leave_encounter',1)]],
    [anyone,'lp_3',[(lt,'$g_encountered_party_attitude',att_cautious),
                    (party_set_slot,'$g_encountered_party',slot_spawn_att_to_player,att_hostile),
                    (store_faction_of_party,':faction','$g_encountered_party'),
                    (call_script,'script_modify_relation_with_player',':faction',-2),
                    (party_get_slot,':origin','$g_encountered_party',slot_spawn_origin),
                    (call_script,'script_modify_town_fame',':origin',-3),
                    ],
     "I know more of you than I care too, {playername}. Now you die!.",'close_window',[]],
# Trade caravan dialogs
	[anyone,'start',
		[
			(eq,'$g_encountered_party_template','pt_trade_caravan'),
			(party_get_slot,':origin','$g_encountered_party',slot_spawn_origin),
			(party_get_slot,':dest','$g_encountered_party',slot_spawn_dest),
			(party_get_slot,':orders','$g_encountered_party',slot_spawn_orders),
			(str_store_party_name,s11,':origin'),
			(str_store_party_name,s12,':dest'),
			(try_begin),
				(eq,':orders',orders_caravan_mutual_trade),
				(str_store_string,s13,'@mutual trade'),
			(else_try),
				(eq,':orders',orders_caravan_trade),
				(str_store_string,s13,'@trade'),
			(else_try),
				(eq,':orders',orders_caravan_return),
				(str_store_string,s13,'@return'),
			(else_try),
				(eq,':orders',orders_caravan_inquire),
				(str_store_string,s13,'@inquiry'),
			(try_end),
			],
		'Greetings. This is the caravan from {s11} to {s12}. Our orders are {s13}.','trade_caravan_demands',[]],
	[anyone,'trade_caravan_demands',
		[
			(eq,1,1),
			(party_get_slot,':demand_array','$g_encountered_party',slot_spawn_caravan_demand_array),
			(str_clear,s10),
			(str_store_string,s10,'@Demands:^'),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_peek',':demand_array',':array_index'),
				(assign,':demand_qty','$return'),
				(gt,':demand_qty',0),
				(store_add,':item_no',':array_index',trade_goods_begin),
				(str_store_item_name,s11,':item_no'),
				(assign,reg10,':demand_qty'),
				(str_store_string,s10,'@{s10}{s11}: {reg10}; '),
			(try_end),
			],
		'{s10}','trade_caravan_supply',[]],
	[anyone,'trade_caravan_supply',
		[
			(eq,1,1),
			(party_get_slot,':goods_array','$g_encountered_party',slot_spawn_caravan_inv_array),
			(str_clear,s10),
			(str_store_string,s10,'@Supply:^'),
			(try_for_range,':array_index',0,num_trade_goods),
				(call_script,'script_array_peek',':goods_array',':array_index'),
				(assign,':supply_qty','$return'),
				(gt,':supply_qty',0),
				(store_add,':item_no',':array_index',trade_goods_begin),
				(str_store_item_name,s11,':item_no'),
				(assign,reg10,':supply_qty'),
				(str_store_string,s10,'@{s10}{s11}: {reg10}; '),
			(try_end),
			],
		'{s10}','trade_caravan_end',[]],
	[anyone,'trade_caravan_end',[],'Good day.','close_window',[]],
# Supply Train dialogs
    [anyone,'start',
		[
			(eq,'$g_encountered_party_template','pt_hosokawa_supply_train'),
			(eq,'$g_talk_context',tc_party_encounter),
			# (party_get_slot,'$party_attitude','$g_encountered_party',slot_spawn_att_to_player),
			# (assign,reg1,'$party_attitude'),
			# (call_script,'script_display_attitude','$party_attitude'),
			],
     "We are delivering supplies on orders from the Hosokawa daimyo.",'st_1',[]],
    [anyone,'start',
		[
			(eq,'$g_encountered_party_template','pt_yamana_supply_train'),
			(eq,'$g_talk_context',tc_party_encounter),
			# (party_get_slot,'$party_attitude','$g_encountered_party',slot_spawn_att_to_player),
			# (assign,reg1,'$party_attitude'),
			# (call_script,'script_display_attitude','$party_attitude'),
			],
     "We are delivering supplies on orders from the Yamana daimyo.",'st_1',[]],
    [anyone|plyr,'st_1',
		[
			(store_faction_of_party,':encountered_party_faction','$g_encountered_party'),
			(try_begin),
				(check_quest_active,'qst_faction_hosokawa'),
				(eq,'fac_hosokawa',':encountered_party_faction'),
				(eq,'$g_dialog_state',ds_friendly),
			(else_try),
				(check_quest_active,'qst_faction_yamana'),
				(eq,'fac_yamana',':encountered_party_faction'),
				(eq,'$g_dialog_state',ds_friendly),
			(try_end),
			(eq,'$g_dialog_state',ds_friendly),
			],
     "Very well. Be on your way.",'close_window',[(assign,'$g_leave_encounter',1)]],
    [anyone|plyr,'st_1',
		[
			(assign,'$g_dialog_state',0),
			(store_faction_of_party,':encountered_party_faction','$g_encountered_party'),
			(try_begin),
				(check_quest_active,'qst_faction_hosokawa'),
				(assign,':faction','fac_hosokawa'),
				(faction_get_slot,':enemy_faction',':faction',slot_faction_enemy_faction),
				(eq,':enemy_faction',':encountered_party_faction'),
				(eq,'$g_dialog_state',ds_combative),
			(else_try),
				(check_quest_active,'qst_faction_yamana'),
				(assign,':faction','fac_yamana'),
				(faction_get_slot,':enemy_faction',':faction',slot_faction_enemy_faction),
				(eq,':enemy_faction',':encountered_party_faction'),
				(eq,'$g_dialog_state',ds_combative),
			(try_end),
			(eq,'$g_dialog_state',ds_combative),
			],
     "Not anymore, you're not. I'll be taking them instead",'st_attack',
     [
         (store_faction_of_party,':encountered_party_faction','$g_encountered_party'),
         (call_script,'script_modify_relation_with_player',':encountered_party_faction',-1),
         (party_set_slot,'$g_encountered_party',slot_spawn_att_to_player,att_hostile),
         ]],
    [anyone|plyr,'st_1',
		[
			(assign,'$g_dialog_state',0),
			(store_faction_of_party,':faction','$g_encountered_party'),
			(try_begin),
				(eq,':faction','fac_hosokawa'),
				(faction_slot_neq,'fac_hosokawa',slot_faction_joined,1),
				(assign,'$g_dialog_state',ds_neutral),
			(else_try),
				(eq,':faction','fac_yamana'),
				(faction_slot_neq,'fac_yamana',slot_faction_joined,1),
				(assign,'$g_dialog_state',ds_neutral),
			(try_end),
			(eq,'$g_dialog_state',ds_neutral),
			],
     "Be on your way, then. Good day.",'close_window',[(assign,'$g_leave_encounter',1)]],
    [anyone|plyr,'st_1',
		[
			(assign,'$g_dialog_state',0),
			(store_faction_of_party,':faction','$g_encountered_party'),
			(try_begin),
				(eq,':faction','fac_hosokawa'),
				(faction_slot_neq,'fac_hosokawa',slot_faction_joined,1),
				(assign,'$g_dialog_state',ds_combative),
			(else_try),
				(eq,':faction','fac_yamana'),
				(faction_slot_neq,'fac_yamana',slot_faction_joined,1),
				(assign,'$g_dialog_state',ds_combative),
			(try_end),
			(eq,'$g_dialog_state',ds_combative),
			],
     "I think I'll help myself to your wares.",'st_attack',
     [
         (store_faction_of_party,':encountered_party_faction','$g_encountered_party'),
         (call_script,'script_modify_relation_with_player',':encountered_party_faction',-1),
         (party_set_slot,'$g_encountered_party',slot_spawn_att_to_player,att_hostile),
         ]],
    [anyone,'st_attack',[],'My men will defeat you. To Arms!','close_window',[]],
    
#Party template dialogs
    [party_tpl|pt_traveling_farmers,"start",
     [(party_get_slot,reg1,'$g_encountered_party',slot_spawn_origin),
      (party_get_slot,reg2,'$g_encountered_party',slot_spawn_dest),
      (str_store_party_name,1,reg1),
      (str_store_party_name,2,reg2)],
     "We are simple farmers from {s1} going to market to sell our wares at {s2}.","close_window",[(assign,'$g_leave_encounter',1)]],
    [party_tpl|pt_traveling_peddler,"start",
     [(party_get_slot,reg1,'$g_encountered_party',slot_spawn_origin),
      (str_store_party_name,1,reg1)],
     "I am a travelling merchant from {s1}.",'close_window',[(assign,'$g_leave_encounter',1)]],
    [trp_merchant,'start',[],'Greetings, traveller.','field_merchant_1',[]],
    [anyone|plyr,'field_merchant_1',[],'I assume you have goods to sell?','field_merchant_2',[]],
    [anyone|plyr,'field_merchant_1',[],'Good day to you.','close_window',[]],
    [anyone,'field_merchant_2',[],'As a matter of fact, I do. Please, have a look.','field_merchant_end',
		[
		 (reset_item_probabilities,100),
         (troop_add_merchandise,'$g_conversation_troop',itp_type_goods,12),
         (troop_add_merchandise,'$g_conversation_troop',itp_type_horse,3),
         (store_random_in_range,reg52,3600,18000),
         (troop_add_gold,'$g_conversation_troop',reg52),
         (troop_ensure_inventory_space,'$g_conversation_troop',12),
         (change_screen_trade)]],
    [anyone,'field_merchant_end',[],'Thank you for your business.','close_window',[]],
    [party_tpl|pt_wealthy_traveller,"start",[],"I have no time for you.","close_window",[(assign,'$g_leave_encounter',1)]],
    [party_tpl|pt_samurai_retinue,"start",[],"I have no time for you.","close_window",[(assign,'$g_leave_encounter',1)]],
    [party_tpl|pt_hosokawa_allied_patrol,"start",
     [(party_get_slot,'$party_attitude','$g_encountered_party',slot_spawn_att_to_player),
      (call_script,'script_display_attitude','$party_attitude')],
     "Halt! Who goes there?","allied_patrol_1",[]],
    [party_tpl|pt_yamana_allied_patrol,"start",
     [(party_get_slot,'$party_attitude','$g_encountered_party',slot_spawn_att_to_player),
      (call_script,'script_display_attitude','$party_attitude')],
     "Halt! Who goes there?","allied_patrol_1",[]],
    [anyone|plyr,"allied_patrol_1",[],"I am just a simple traveller.","allied_patrol_2",[]],
    [anyone|plyr,"allied_patrol_1",[],"I am {playername}.","ap_3",
     [
        (store_faction_of_party,reg2,'$g_encountered_party'),
        (faction_get_slot,reg3,reg2,slot_faction_hosokawa_ally),
        (try_begin),
                (eq,reg3,1),
                (assign,':input_faction',"fac_yamana"),
        (else_try),
                (assign,':input_faction',"fac_hosokawa"),
        (try_end),
        (call_script,"script_player_has_faction_troops",'p_main_party',':input_faction'),
		(assign,'$enemy_troops_present','$return')]],
    [anyone,"allied_patrol_2",[(le,'$party_attitude',att_defensive)],
     "Liar! I will have your head!","close_window",[(store_faction_of_party,reg2,'$g_encountered_party'),
                                                    (call_script,'script_modify_relation_with_player',reg2,-2),
                                                    (party_set_slot,'$g_encountered_party',slot_spawn_att_to_player,att_hostile),
                                                    (encounter_attack,0)]],
    [anyone,"allied_patrol_2",[(this_or_next|eq,'$party_attitude',att_cautious),
                               (eq,'$party_attitude',att_secretive)],"Very well. You may pass.","close_window",[(assign,'$g_leave_encounter',1)]],
    [anyone,"allied_patrol_2",[(ge,'$party_attitude',att_friendly)],"Indeed. Beware of our enemies.","close_window",[(assign,'$g_leave_encounter',1)]],
    [anyone,"ap_3",[(eq,"$party_attitude",att_generous),
                    (eq,'$enemy_troops_present',1)],
     "You are well known to me, {playername}. It confounds me that you would keep company with our enemy.","close_window",[(assign,'$g_leave_encounter',1)]],
    [anyone,"ap_3",[(eq,"$party_attitude",att_generous)],
     "You are well known to my men and I, {playername}. It is good to have met you.","close_window",[(assign,'$g_leave_encounter',1)]],
    [anyone,"ap_3",[(eq,"$party_attitude",att_friendly),
                    (eq,'$enemy_troops_present',1)],
     "Though I have heard your name before, {playername}, I am deeply troubled by the company you keep. I shall have to report this to the shugo",
     "close_window",
     [
         (store_faction_of_party,reg3,'$g_encountered_party'),
         (call_script,"script_modify_relation_with_player",reg3,-1),
         (assign,'$g_leave_encounter',1)]],
    [anyone,"ap_3",[(eq,"$party_attitude",att_friendly)],
     "I have heard of you before, {playername}. Be well on your journey.","close_window",[(assign,'$g_leave_encounter',1)]],
    [anyone,"ap_3",[(eq,"$party_attitude",att_cautious),
                    (eq,'$enemy_troops_present',1)],
     "That means nothing to me. Furthermore, you travel in the company of my enemy.","ap_fight",[]],
    [anyone,"ap_3",[(eq,"$party_attitude",att_cautious)],
     "That means nothing to me. Good day.","close_window",[(assign,'$g_leave_encounter',1)]],
    [anyone,"ap_3",[(lt,"$party_attitude",att_cautious)],
     "Very well, {playername}.","ap_fight",[]],
    [anyone,"ap_fight",[(party_set_slot,'$g_encountered_party',slot_spawn_att_to_player,att_hostile)],"Now you die","close_window",
     [
         (store_faction_of_party,reg1,'$g_encountered_party'),
         (call_script,"script_modify_relation_with_player",reg1,-1),
         (encounter_attack,0)]],
    [party_tpl|pt_wanderer,"start",[],"Greetings...","wanderer_1",[]],
    [anyone|plyr,"wanderer_1",[],"Perhaps you would join me.","wanderer_2",[(store_random_in_range,"$wanderer_answer",0,2)]],
    [anyone,"wanderer_2",[(eq,"$wanderer_answer",0)],"No. I have not wandered long enough.","close_window",[(assign,'$g_leave_encounter',1)]],
    [anyone,"wanderer_2",[(eq,"$wanderer_answer",1),(party_can_join)],"Yes. I have wandered long enough.","close_window",[(party_join)]],
    [anyone,"wanderer_2",[(eq,"$wanderer_answer",1),(neg|party_can_join)],"Yes, but you have no room.","close_window",[(assign,'$g_leave_encounter',1)]],
    [party_tpl|pt_ikko_ikki_rabble,"start",[],"You serve the corrupt Shogun. For that, you will die.","close_window",[]],
    [party_tpl|pt_ikko_ikki_rebels,"start",[],"You serve the corrupt Shogun. For that, you will die.","close_window",[]],
    [party_tpl|pt_ikko_ikki_insurgents,"start",[],"You serve the corrupt Shogun. For that, you will die.","close_window",[]],
    [party_tpl|pt_travellers,"start",[],"We are just travellers on the wheel of karma.","close_window",[]],
    [party_tpl|pt_pilgrims,"start",[],"We seek Buddha's blessing at Enryaku-ji.","close_window",[]],
    [party_tpl|pt_monk_pilgrim,"start",[],"I seek further enlightenment at Enryaku-ji.","close_window",[(assign,'$g_leave_encounter',1)]],
    [party_tpl|pt_refugees,"start",[],"We are fleeing the violence in Kyoto.","close_window",[(assign,'$g_leave_encounter',1)]],
    [party_tpl|pt_yamabushi,"start",[],"Greetings...","yamabushi_1",[]],
    [anyone|plyr,"yamabushi_1",[],"Perhaps you would join me.","yamabushi_2",[(store_random_in_range,"$wanderer_answer",0,2)]],
    [anyone,"yamabushi_2",[(eq,"$wanderer_answer",0)],"No. I have not wandered long enough.","close_window",[(assign,'$g_leave_encounter',1)]],
    [anyone,"yamabushi_2",[(eq,"$wanderer_answer",1),(party_can_join)],"Yes. I have wandered long enough.","close_window",[(party_join)]],
    [anyone,"yamabushi_2",[(eq,"$wanderer_answer",1),(neg|party_can_join)],"Yes, but you have no room.","close_window",[]],
    [party_tpl|pt_messenger,"start",[],"I have no time to talk. Good bye.","close_window",[]],
    [anyone,'start',
		[
			(eq,'$g_talk_context',tc_party_encounter),
			(this_or_next|eq,'$g_encountered_party_template','pt_river_pirates'),
			(this_or_next|eq,'$g_encountered_party_template','pt_bandits'),
			(this_or_next|eq,'$g_encountered_party_template','pt_forest_bandits'),
			(this_or_next|eq,'$g_encountered_party_template','pt_mountain_bandits'),
			(eq,'$g_encountered_party_template','pt_sea_raiders'),
			],
		'Your wealth will be ours. Hand it over or die.','bandit_fight',
		[
			(call_script,'script_modify_relation_with_player','fac_outlaws',-1),
			]],
	[anyone|plyr,"bandit_fight",[],"I pray your next incarnation is better, because this one ends now!","close_window",[]],
    
    [party_tpl|pt_bandits,"start",[(store_encountered_party,reg1),
                                             (eq,reg1,"$intro_bandit_party"),
                                             (eq,"$bandit_intro",1)],
     "What is the password?","bandit_pw",[]],
    [anyone|plyr,"bandit_pw",[],"Miyazaki","bandit_pw2",[(assign,"$pw",1)]],
    [anyone|plyr,"bandit_pw",[],"Hajimemashite","bandit_pw2",[(assign,"$pw",2)]],
    [anyone|plyr,"bandit_pw",[],"Shibboleth","bandit_pw2",[(assign,"$pw",3)]],
    [anyone|plyr,"bandit_pw",[],"Antidisestablishmentarianism","bandit_pw2",[(assign,"$pw",4)]],
    [anyone|plyr,"bandit_pw",[],"Bob","bandit_pw2",[(assign,"$pw",5)]],
    [anyone,"bandit_pw2",[(eq,"$pw",3)],"Very good. Follow me.","close_window",[(jump_to_menu,"mnu_bandit_camp")]],
    [anyone,"bandit_pw2",[(neq,"$pw",3)],"Aw, too bad. Now I'll have to kill you.","close_window",[(encounter_attack,0)]],
    [party_tpl|pt_bandits,"start",[(lt,'$bandits_denied',3),
                                     (check_quest_active,'qst_class_ronin'),
                                     (neq,"$joined_bandits",1),
                                     (faction_slot_eq,'fac_hosokawa',slot_faction_joined,false),
                                     (faction_slot_eq,'fac_yamana',slot_faction_joined,false),
                                     (neq,"$bandit_intro",1)],
     "You look like an unsavory sort of fellow. How would you like to join our band?","join_bandits_1",[]],
    [anyone|plyr,"join_bandits_1",[],"Sounds interesting, and I have nothing better to do.","join_bandits_2",[]],
    [anyone,"join_bandits_2",[(store_encountered_party,"$intro_bandit_party"),(assign,"$bandit_intro",1)],
     "Good choice, friend. Meet me back at our camp, and speak the password 'Shibboleth'.","close_window",[]],
    [anyone|plyr,"join_bandits_1",[],"Looks can be deceiving. I'll never join you!","bandits_denied",
     [(try_begin),
          (neq,'$bandits_denied',1),
          (assign,"$bandits_denied",1),
      (else_try),
          (eq,'$bandits_denied',1),
          (val_add,'$bandits_denied',1),
      (try_end)]],
    [anyone,"bandits_denied",[],"Very well, then. Now you die!","close_window",[(encounter_attack)]],
    [party_tpl|pt_bandits,"start",[(check_quest_active,'qst_subclass_bandit')],"Good to have you with us.","bandit_talk",[]],
	[anyone|plyr,'bandit_talk',[],"I'd like you and your men to join me. Much glory can be had.",'bandits_join',[]],
	[anyone|plyr,'bandit_talk',[],'See you around.','bandits_end',[]],
	[anyone,'bandits_join',[(party_can_join),(call_script,'script_party_add_party','p_main_party','$g_encountered_party')],
		"Sure. We'll follow you.",'close_window',[(assign,'$g_leave_encounter',1)]],
    [anyone,'bandits_join',[],"We would, but you don't seem to have the room.",'close_window',[(assign,'$g_leave_encounter',1)]],
    [anyone,'bandits_end',[],"Likewise.",'close_window',[(assign,'$g_leave_encounter',1)]],
    [party_tpl|pt_bandit_raiders_b,'start',[],'Ha ha! Tremble before my might, {boy/girl}.','raiders_a',[]],
    [anyone|plyr,'raiders_a',[],"Don't flatter yourself. All I see are koban when I look at you.",'raiders_b',[]],
    [anyone,'raiders_b',[],"What? You're a bounty hunter? Argh! Kill them all!",'close_window',[(encounter_attack)]],
    [party_tpl|pt_duelist,"start",[],"I seek to improve my skill with the blade. You look like good fodder.","close_window",[]],
    [party_tpl|pt_rescued_prisoners,"start",[],"Do you want us to follow you?","disbanded_troop_ask",[]],
    [anyone|plyr,"disbanded_troop_ask",[],"Yes, ride with me.","disbanded_troop_join",[]],
    [anyone|plyr,"disbanded_troop_ask",[],"No, not at this time.","close_window",[]],
    [anyone,"disbanded_troop_join",[[neg|party_can_join]],"It would appear that you don't have room for us.",
     "close_window",[]],
    [anyone,"disbanded_troop_join",[],"We are at your command.","close_window",[[party_join]]],

    [anyone,"party_relieved",[],"Thanks for your help.","close_window",[]],

    [party_tpl|pt_enemy,"start", [], "You will not capture me again. Not this time.", "enemy_talk_1",[]],
    [party_tpl|pt_enemy|plyr,"enemy_talk_1", [], "You don't have a chance against me. Give up.", "enemy_talk_2",[]],
    [party_tpl|pt_enemy,"enemy_talk_2", [], "I will give up when you are dead!", "close_window",[[encounter_attack]]],

    # city scene dialogs
    [anyone,'start',
     [
         (store_current_scene,':scene'),
         (eq,':scene','scn_city'),
         (try_for_agents,':agent'),
             (agent_is_alive,':agent'),
             (agent_is_ally,':agent'),
             (agent_is_human,':agent'),
             (agent_get_troop_id,':troop_id',':agent'),
             (this_or_next|eq,':troop_id','trp_t2_heavy_cav_n'),
             (this_or_next|eq,':troop_id','trp_t2_bow_ashigaru_n'),
             (eq,':troop_id','trp_samurai'),
         (try_end)],
     'This is the prefectural manor. Attend to your business and depart.','close_window',[]],
        
		
	[anyone,"party_relieved", [(eq,'$g_talk_context',tc_ally_thanks)], "Thank you for helping us against those bastards.", "close_window",[(assign,'$g_leave_encounter',1)]],

    [anyone,"member_chat", [[store_conversation_troop,reg3],[troop_is_hero,reg3]], "Yes?", "member_talk",[]],
    [anyone|plyr,"member_talk",[],"I have a few items that I no longer need. Would you care to barter?", "member_trade",[]],
    [anyone,"member_trade", [], "Of course. Let me see what you have got.", "do_member_trade",[[change_screen_trade]]],
    [anyone,"do_member_trade", [], "Anything else?", "member_talk",[]],
    [anyone|plyr,"member_talk", [], "Tell me about yourself", "view_member_char_requested",[]],
    [anyone,"view_member_char_requested", [], "All right then, listen to this...",
     "do_member_view_char",[[change_screen_view_character]]],
    [anyone|plyr,"member_talk", [], "We need to seperate for a while.", "member_seperate",[]],
    [anyone,"member_seperate", [], "Seperate? All right. What do you want me to do?", "member_seperate_2",[]],
    [anyone|plyr,"member_seperate_2", [], "You go and wait for me at Itami. I'll find you there.", "member_seperate_site",[]],
    [anyone,"member_seperate_site", [], "All right then, I'll meet you at Itami. Good luck.", "close_window",
    [[store_conversation_troop,reg0],[remove_member_from_party,reg0],(troop_set_slot,reg0,slot_troop_at_inn,1)]],
    [anyone|plyr,"member_seperate_2", [], "Wait for me right here. I will come back for you.", "member_seperate_wilderness",[]],
    [anyone,"member_seperate_wilderness", [], "All right then, I'll wait for you. Hey. Don't you forget to come back for me.", "close_window",
    [[store_conversation_troop,reg0],
     [remove_member_from_party,reg0],
     [add_companion_party,reg0],
     (party_set_ai_behavior,reg0,ai_bhvr_hold)]],
    [anyone|plyr,"member_seperate_2", [], "I changed my mind. You keep following me.", "do_member_trade",[]],
    [anyone,"do_member_view_char", [(str_store_string,1,'@Anything else?')], "{s1}", "member_talk",[]],
	[anyone|plyr,'member_talk',[],'Give me some debugging info.','member_talk_debug',[]],
	[anyone,'member_talk_debug',[],'Well, let me tell ya...','member_debug_2',[]],
	[anyone,'member_debug_2',
	[
		(faction_get_slot,reg1,'fac_hosokawa',slot_faction_att_to_player),
		(faction_get_slot,reg2,'fac_yamana',slot_faction_att_to_player),
		(store_relation,reg3,'fac_player_faction','fac_hosokawa'),
		(store_relation,reg4,'fac_player_faction','fac_yamana'),
		(party_get_slot,reg5,'$g_most_recent_town',slot_town_att_to_player), # need to set this up in the game menus
		(str_store_party_name,1,'$g_most_recent_town'),
		(party_get_slot,reg6,'$g_most_recent_spawn',slot_spawn_att_to_player), # need to set this up too, in simple_encounters
		(str_store_party_name,2,'$g_most_recent_spawn'),
		(party_get_num_companion_stacks,':num_stacks','p_main_party'),
		(assign,reg7,0),
		(assign,reg8,0),
		(assign,reg9,0),
		(assign,':exit_loop',0),
		(try_for_range,':i',1,':num_stacks'),
			(eq,':exit_loop',0),
			(party_stack_get_troop_id,':troop_id','p_main_party',':i'),
			(neg|troop_is_hero,':troop_id'),
			(assign,reg7,':troop_id'),
			(troop_get_slot,reg8,':troop_id',slot_troop_cost),
			(party_stack_get_size,reg9,'p_main_party',':i'),
			(assign,':exit_loop',1),
		(try_end),
		(str_store_troop_name,3,reg7),
		],
	"The attitude of the Hosokawa toward you is {reg1}. The attitude of the Yamana towards you is {reg2}. Your relations with the Hosokawa are {reg3}. Your relations with the Yamana is {reg4}. The attitude towards you of the most recently visited town, {s1}, is {reg5}. The attitude towards you of the most recently encountered spawn, {s2}, is {reg6}. You have {reg9} of your first non-hero troop, {s3}. The weekly upkeep cost of {s3} is {reg8}.",
	'member_debug_3',[]],
	[anyone,'member_debug_3',
		[
			(troop_get_slot,reg1,'trp_mitsumaru',slot_sensei_weapon_type),
			(troop_get_slot,reg2,'trp_tomomoto',slot_sensei_weapon_type),
			(troop_get_slot,reg3,'trp_teruhisa',slot_sensei_weapon_type),
			(troop_get_slot,reg4,'trp_kiyouji',slot_sensei_weapon_type),
			(troop_get_slot,reg5,'trp_ietsuru',slot_sensei_weapon_type),
			(troop_get_slot,reg6,'trp_tsunetomo',slot_sensei_weapon_type),
			(troop_get_slot,reg7,'trp_ujiaru',slot_sensei_weapon_type),
			(troop_get_slot,reg8,'trp_michimori',slot_sensei_weapon_type),
			],
		"Sensei weapon types are: {reg1} {reg2} {reg3} {reg4} {reg5} {reg6} {reg7} {reg8}",
		'member_debug_end',[]],
	[anyone,'member_debug_end',[],'That is all.','member_talk',[]],
    [anyone|plyr,"member_talk", [], "Nothing. Let us keep riding.", "close_window",[]],
    
    [anyone,"member_chat", [], "Your orders {sir/madam}?", "regular_member_talk",[]],
    [anyone|plyr,"regular_member_talk",
		[
			(store_conversation_troop,reg1),
			(troop_is_hero,reg1),
			],
		"I have a few items that I no longer need. Would you care to barter?", "member_trade",[]],
    [anyone,"member_trade", [], "Of course. Let me see what you have got.", "do_member_trade",[[change_screen_trade]]],
    [anyone,"do_member_trade", [], "Anything else?", "regular_member_talk",[]],
    [anyone|plyr,"regular_member_talk", [], "Tell me about yourself", "view_regular_char_requested",[]],
    [anyone,"view_regular_char_requested", [], "Aye {sir/madam}. Let me tell you all there is to know about me.", "do_regular_member_view_char",[[change_screen_view_character]]],
    [anyone,"do_regular_member_view_char", [], "Anything else?", "regular_member_talk",[]],
    [anyone|plyr,"regular_member_talk", [], "Nothing. Keep moving.", "close_window",[]],

    #[anyone|plyr,"member_wilderness_talk", [], "Yes. Follow me.", "member_wilderness_join",[]],
    #[anyone,"member_wilderness_join", [[neg|party_can_join]],
    #"Darn. I am afraid you do not have enough capacity in your party for me. Why don't you try again after fixing that?", "close_window",[]],
    #[anyone,"member_wilderness_join", [], "Good. I was beginning to get bored.", "close_window",[[party_join]]],
    #[anyone|plyr,"member_wilderness_talk", [], "No. Stay here for a while longer.", "member_wilderness_no_join",[]],
    #[anyone,"member_wilderness_no_join", [], "All right. All right. You go and take care of your important business. Don't even think about me. What job have I got in life other than waiting for you in this God forsaken place?", "close_window",[]],
    #[anyone|plyr,"member_wilderness_talk_talk", [], "I want to leave some troops with you.", "member_wilderness_leave_troops",[]],
    #[anyone,"member_wilderness_leave_troops", [], "Really? Well, you can trust me. I will command them well.", "member_wilderness_leave_troops_2",[[change_screen_exchange_members]]],
    #[anyone,"member_wilderness_leave_troops_2", [], "We will be waiting for you here. Be careful.", "close_window",[]],

    [anyone|plyr,"member_inn_talk", [], "Yes. Let us ride together again.", "member_inn_join",[]],
    [anyone,"member_inn_join", [[neg|hero_can_join]],
    "Darn. I am afraid you do not have enough capacity in your party for me. Why don't you try again after fixing that?", "close_window",[]],
    [anyone,"member_inn_join", [], "Good. I was beginning to get bored.", "close_window",
     [[store_conversation_troop,reg0],[troop_join,reg0],(troop_set_slot,reg0,slot_troop_at_inn,0),[remove_troop_from_site,reg0]]],
    [anyone|plyr,"member_inn_talk", [], "No. Stay here for a while longer.", "member_inn_no_join",[]],
    [anyone,"member_inn_no_join", [], "All right. All right. You go and take care of your important business. Don't even mind about me. What job have I got in life other than waiting for you in some country inn?", "close_window",[]],

    [anyone,"prisoner_chat",[],"What do you want?","prisoner_chat_1",[]],
    [anyone|plyr,"prisoner_chat_1",[],"Never mind.","close_window",[]],
    [anyone|plyr,"prisoner_chat_1",[],"How would you like to join my band?","prisoner_join",[]],
    [anyone,"prisoner_join",[],"I'd rather have a snake suck on my left toe.","close_window",[]],

#Last dialog (add none after here)
    [anyone,"start", [], "Hello. What can I do for you?", "free",[]],
    [anyone|plyr,"free", [[neg|in_meta_mission]], "Tell me about yourself", "view_char_requested",[]],
    [anyone,"view_char_requested", [], "Ok then listen to this...", "view_char",[[change_screen_view_character]]],
    [anyone,"view_char", [], "Anything else?", "free",[]],
    [anyone|plyr,"free", [[in_meta_mission]], " Good-bye.", "close_window",[]],
    [anyone|plyr,"free", [[neg|in_meta_mission]], " [Leave]", "close_window",[]],
    ]
